Skip to content

Commit 4d6ed5c

Browse files
igorbrasileiromatheusgr
authored andcommitted
Change custom lastId to use revision
1 parent 3ff5379 commit 4d6ed5c

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

engine/schema/builder.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,18 @@ function fileUniqueId(
171171
return [btoa(fileUrl), fileUrl];
172172
}
173173

174-
let lastId = 0;
175-
export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
174+
export const newSchemaBuilder = (
175+
initial: SchemaData,
176+
revision: string,
177+
): SchemaBuilder => {
176178
return {
177179
data: initial,
178180
withBlockSchema(schema: BlockModule | EntrypointModule): SchemaBuilder {
179181
if (isEntrypoint(schema)) {
180182
return newSchemaBuilder({
181183
...initial,
182184
entrypoints: [...initial.entrypoints, schema],
183-
});
185+
}, revision);
184186
}
185187
// routes is always entrypoints
186188
if (schema.blockType === "routes" && schema.inputSchema) {
@@ -193,15 +195,14 @@ export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
193195
config: schema.inputSchema,
194196
},
195197
],
196-
});
198+
}, revision);
197199
}
198200
return newSchemaBuilder({
199201
...initial,
200202
blockModules: [...initial.blockModules, schema],
201-
});
203+
}, revision);
202204
},
203205
build() {
204-
// lastId = 0;
205206
const schemeableId = (
206207
schemeable: Schemeable,
207208
resolvePath = true,
@@ -371,7 +372,7 @@ export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
371372

372373
const finalDefsWith$id = Object.fromEntries(
373374
Object.entries(finalDefs).map((entry, idx) => {
374-
entry[1] = { ...entry[1], $id: `#/${idx}-${lastId}` };
375+
entry[1] = { ...entry[1], $id: `#/${idx}-${revision}` };
375376
return entry;
376377
}),
377378
);

engine/schema/gen.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ const resolveImport = (path: string) => {
6565

6666
export const genSchemasFromManifest = async (
6767
manifest: AppManifest,
68-
baseDir?: string,
68+
baseDir: string | undefined = undefined,
6969
importMap: ImportMap = { imports: {} },
70+
revision: Promise<string>,
7071
): Promise<Schemas> => {
7172
const { baseUrl: _ignore, name: _ignoreName, ...manifestBlocks } = manifest;
7273
const dir = toFileUrl(baseDir ? baseDir : Deno.cwd()).toString();
@@ -82,11 +83,12 @@ export const genSchemasFromManifest = async (
8283
},
8384
{} as Record<string, JSONSchema7>,
8485
);
86+
const rev = await revision;
8587
const schemaBuilder = newSchemaBuilder({
8688
schema: { root: rootWithBlocks, definitions: {} },
8789
blockModules: [],
8890
entrypoints: [],
89-
});
91+
}, rev);
9092

9193
const refPromises: Promise<
9294
(BlockModule | EntrypointModule | undefined)

engine/schema/lazy.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export const lazySchemaFor = (ctx: Omit<DecoContext, "schema">): LazySchema => {
154154
const { manifest, importMap } = await ctx.runtime!;
155155
_cached = incorporateSavedBlocksIntoSchema(
156156
manifest,
157-
await genSchemas(manifest, importMap),
157+
await genSchemas(
158+
manifest,
159+
importMap,
160+
ctx.release?.revision() ?? Promise.resolve(""),
161+
),
158162
{
159163
...await ctx.release!.state(),
160164
},

engine/schema/reader.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import type { AppManifest } from "../../types.ts";
77
export const genSchemas = async (
88
manifest: AppManifest,
99
importMap: ImportMap = { imports: {} },
10+
revision: Promise<string>,
1011
) => {
1112
const base = Deno.cwd();
1213
const schema = await genSchemasFromManifest(
1314
manifest,
1415
base,
1516
importMap,
17+
revision,
1618
);
1719

1820
if (!context.isDeploy) {

0 commit comments

Comments
 (0)