@powerhousedao/codegen 6.2.2-dev.41 → 6.2.2-dev.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5185,36 +5185,88 @@ ${buildCreatorsExports(v.specification.modules, v.camelCaseDocumentType)}
5185
5185
  `.raw;
5186
5186
  //#endregion
5187
5187
  //#region src/templates/document-model/gen/document-schema.ts
5188
- const documentModelDocumentSchemaFileTemplate = (v) => ts$1`
5188
+ function priorVersions(versions, currentVersion) {
5189
+ return versions.filter((k) => k < currentVersion);
5190
+ }
5191
+ function makeOlderStateSchemaImports(versions, currentVersion, phStateName) {
5192
+ return priorVersions(versions, currentVersion).map((k) => `import { ${phStateName}Schema as ${phStateName}SchemaV${k} } from "../../v${k}/gen/document-schema.js";`).join("\n");
5193
+ }
5194
+ function makeStateSchemasByVersion(versions, currentVersion, phStateName) {
5195
+ return `{ ${versions.filter((k) => k <= currentVersion).map((k) => {
5196
+ return `${k}: ${k === currentVersion ? `${phStateName}Schema` : `${phStateName}SchemaV${k}`}`;
5197
+ }).join(", ")} }`;
5198
+ }
5199
+ function makeDocumentSchemasByVersion(versions, currentVersion, v) {
5200
+ return `{ ${versions.filter((k) => k <= currentVersion).map((k) => {
5201
+ if (k === currentVersion) return `${k}: ${v.phDocumentSchemaName}`;
5202
+ return `${k}: z.object({ header: ${v.phDocumentTypeName}HeaderSchema, state: ${v.phStateName}SchemaV${k}, initialState: ${v.phStateName}SchemaV${k} })`;
5203
+ }).join(", ")} }`;
5204
+ }
5189
5205
  /**
5190
- * WARNING: DO NOT EDIT
5191
- * This file is auto-generated and updated by codegen
5192
- */
5193
- import {
5194
- BaseDocumentHeaderSchema,
5195
- BaseDocumentStateSchema,
5196
- } from "document-model";
5197
- import { z } from "zod";
5198
- import { ${v.documentTypeVariableName} } from "./document-type.js";
5199
- import { ${v.stateSchemaName} } from "./schema/zod.js";
5200
- import type { ${v.phDocumentTypeName}, ${v.phStateName} } from "./types.js";
5206
+ * Version-aware validators are only emitted for versions with released
5207
+ * predecessors: a document is validated against the schema of the version it
5208
+ * is stamped with, so a later version may add non-nullable fields without
5209
+ * rejecting documents that have not been upgraded yet.
5210
+ */
5211
+ function makeVersionAwareValidators(v) {
5212
+ return `
5213
+ const ${v.phStateName}SchemasByVersion: Record<number, z.ZodType> = ${makeStateSchemasByVersion(v.versions, v.version, v.phStateName)};
5201
5214
 
5202
- /** Schema for validating the header object of a ${v.pascalCaseDocumentType} document */
5203
- export const ${v.phDocumentTypeName}HeaderSchema = BaseDocumentHeaderSchema.extend({
5204
- documentType: z.literal(${v.documentTypeVariableName}),
5205
- });
5215
+ const ${v.phDocumentSchemaName}sByVersion: Record<number, z.ZodType> = ${makeDocumentSchemasByVersion(v.versions, v.version, v)};
5206
5216
 
5207
- /** Schema for validating the state object of a ${v.pascalCaseDocumentType} document */
5208
- export const ${v.phStateName}Schema = BaseDocumentStateSchema.extend({
5209
- global: ${v.stateSchemaName}(),
5210
- });
5217
+ /** The document model version stamped in a state's document scope. States stamped with 0 or nothing predate versioning and are treated as version 1. */
5218
+ function stampedDocumentModelVersion(state: unknown): number {
5219
+ if (typeof state !== "object" || state === null) return 1;
5220
+ const documentScope = (state as { document?: unknown }).document;
5221
+ if (typeof documentScope !== "object" || documentScope === null) return 1;
5222
+ const version = (documentScope as { version?: unknown }).version;
5223
+ return normalizeDocumentModelVersion(typeof version === "number" ? version : undefined);
5224
+ }
5211
5225
 
5212
- export const ${v.phDocumentSchemaName} = z.object({
5213
- header: ${v.phDocumentTypeName}HeaderSchema,
5214
- state: ${v.phStateName}Schema,
5215
- initialState: ${v.phStateName}Schema,
5216
- });
5226
+ function resolve${v.phStateName}Schema(state: unknown): z.ZodType {
5227
+ const schema = ${v.phStateName}SchemasByVersion[stampedDocumentModelVersion(state)];
5228
+ return schema ?? ${v.phStateName}Schema;
5229
+ }
5230
+
5231
+ function resolve${v.phDocumentSchemaName}(document: unknown): z.ZodType {
5232
+ const state = typeof document === "object" && document !== null
5233
+ ? (document as { state?: unknown }).state
5234
+ : undefined;
5235
+ const schema = ${v.phDocumentSchemaName}sByVersion[stampedDocumentModelVersion(state)];
5236
+ return schema ?? ${v.phDocumentSchemaName};
5237
+ }
5238
+
5239
+ /** Simple helper function to check if a state object is a ${v.pascalCaseDocumentType} document state object. Validates against the schema of the version the state is stamped with. */
5240
+ export function ${v.isPhStateOfTypeFunctionName}(
5241
+ state: unknown,
5242
+ ): state is ${v.phStateName} {
5243
+ return resolve${v.phStateName}Schema(state).safeParse(state).success;
5244
+ }
5245
+
5246
+ /** Simple helper function to assert that a document state object is a ${v.pascalCaseDocumentType} document state object. Validates against the schema of the version the state is stamped with. */
5247
+ export function ${v.assertIsPhStateOfTypeFunctionName}(
5248
+ state: unknown,
5249
+ ): asserts state is ${v.phStateName} {
5250
+ resolve${v.phStateName}Schema(state).parse(state);
5251
+ }
5252
+
5253
+ /** Simple helper function to check if a document is a ${v.pascalCaseDocumentType} document. Validates against the schema of the version the document is stamped with, so documents on older versions remain valid until they are upgraded. */
5254
+ export function ${v.isPhDocumentOfTypeFunctionName}(
5255
+ document: unknown,
5256
+ ): document is ${v.phDocumentTypeName} {
5257
+ return resolve${v.phDocumentSchemaName}(document).safeParse(document).success;
5258
+ }
5217
5259
 
5260
+ /** Simple helper function to assert that a document is a ${v.pascalCaseDocumentType} document. Validates against the schema of the version the document is stamped with, so documents on older versions remain valid until they are upgraded. */
5261
+ export function ${v.assertIsPhDocumentOfTypeFunctionName}(
5262
+ document: unknown,
5263
+ ): asserts document is ${v.phDocumentTypeName} {
5264
+ resolve${v.phDocumentSchemaName}(document).parse(document);
5265
+ }
5266
+ `;
5267
+ }
5268
+ function makeSingleVersionValidators(v) {
5269
+ return `
5218
5270
  /** Simple helper function to check if a state object is a ${v.pascalCaseDocumentType} document state object */
5219
5271
  export function ${v.isPhStateOfTypeFunctionName}(
5220
5272
  state: unknown,
@@ -5242,7 +5294,42 @@ export function ${v.assertIsPhDocumentOfTypeFunctionName}(
5242
5294
  ): asserts document is ${v.phDocumentTypeName} {
5243
5295
  ${v.phDocumentSchemaName}.parse(document);
5244
5296
  }
5245
- `.raw;
5297
+ `;
5298
+ }
5299
+ const documentModelDocumentSchemaFileTemplate = (v) => {
5300
+ const olderImports = makeOlderStateSchemaImports(v.versions, v.version, v.phStateName);
5301
+ const hasPriorVersions = olderImports.length > 0;
5302
+ return ts$1`
5303
+ /**
5304
+ * WARNING: DO NOT EDIT
5305
+ * This file is auto-generated and updated by codegen
5306
+ */
5307
+ import {
5308
+ BaseDocumentHeaderSchema,
5309
+ BaseDocumentStateSchema,${hasPriorVersions ? "\n normalizeDocumentModelVersion," : ""}
5310
+ } from "document-model";
5311
+ import { z } from "zod";
5312
+ import { ${v.documentTypeVariableName} } from "./document-type.js";
5313
+ import { ${v.stateSchemaName} } from "./schema/zod.js";
5314
+ import type { ${v.phDocumentTypeName}, ${v.phStateName} } from "./types.js";
5315
+ ${hasPriorVersions ? olderImports + "\n" : ""}
5316
+ /** Schema for validating the header object of a ${v.pascalCaseDocumentType} document */
5317
+ export const ${v.phDocumentTypeName}HeaderSchema = BaseDocumentHeaderSchema.extend({
5318
+ documentType: z.literal(${v.documentTypeVariableName}),
5319
+ });
5320
+
5321
+ /** Schema for validating the state object of a ${v.pascalCaseDocumentType} document */
5322
+ export const ${v.phStateName}Schema = BaseDocumentStateSchema.extend({
5323
+ global: ${v.stateSchemaName}(),
5324
+ });
5325
+
5326
+ export const ${v.phDocumentSchemaName} = z.object({
5327
+ header: ${v.phDocumentTypeName}HeaderSchema,
5328
+ state: ${v.phStateName}Schema,
5329
+ initialState: ${v.phStateName}Schema,
5330
+ });
5331
+ ${hasPriorVersions ? makeVersionAwareValidators(v) : makeSingleVersionValidators(v)}`.raw;
5332
+ };
5246
5333
  //#endregion
5247
5334
  //#region src/templates/document-model/gen/document-type.ts
5248
5335
  const documentModelDocumentTypeTemplate = (v) => ts$1`
@@ -8720,4 +8807,4 @@ async function makeSubgraphsIndexFile(args) {
8720
8807
  //#endregion
8721
8808
  export { getVariableDeclarationByTypeName as $, upgradeManifestsTemplate as $n, documentModelPhFactoriesFileTemplate as $t, writeGeneratedProcessorsFiles as A, readmeTemplate as An, factoryBuildersTemplate as At, updateVersionedImports as B, mainTsxTemplate as Bn, makeOperationImportNames as Bt, buildBoilerplatePackageJson as C, documentEditorEditorFileTemplate as Cn, relationalDbSchemaTemplate as Ct, writeCIFiles as D, tsconfigPathsTemplate as Dn, relationalDbFactoryTemplate as Dt, writeAllGeneratedProjectFiles as E, tsConfigTemplate as En, relationalDbIndexTemplate as Et, tsMorphGenerateApp as F, pnpmWorkspaceTemplate as Fn, renderProcessorFilter as Ft, getAllImportModuleSpecifiers as G, indexHtmlTemplate as Gn, documentModelSrcIndexFileTemplate as Gt, DEFAULT_PROJECT_OPTIONS as H, reactorTsTemplate as Hn, makeTestCaseForOperation as Ht, makeEditorModuleFile as I, exportsTemplate as In, documentModelUtilsTemplate as It, getObjectLiteral as J, geminiSettingsTemplate as Jn, documentModelHooksFileTemplate as Jt, getAllImportNames as K, gitIgnoreTemplate as Kn, documentModelModuleFileTemplate as Kt, makeEditorsFile as L, packageJsonTemplate as Ln, upgradeTransitionTemplate as Lt, writeGeneratedSubgraphsFiles as M, buildPowerhouseConfigTemplate as Mn, analyticsIndexTemplate as Mt, writeModuleFiles as N, packageJsonExportsTemplate as Nn, analyticsFactoryTemplate as Nt, writeGeneratedDocumentModelsFiles as O, subgraphsIndexTemplate as On, processorsIndexTemplate as Ot, writeProjectRootFiles as P, packageJsonScriptsTemplate as Pn, parseFilterValues as Pt, getStringPropertyValue as Q, editorsTemplate as Qn, documentModelGenReducerFileTemplate as Qt, makeEditorsIndexFile as R, npmrcTemplate as Rn, upgradeManifestTemplate as Rt, writeCliDocsMarkdownFile as S, documentEditorModuleFileTemplate as Sn, subgraphIndexFileTemplate as St, writeAiConfigFiles as T, vitestConfigTemplate as Tn, relationalDbMigrationsTemplate as Tt, buildTsMorphProject as U, indexTsTemplate as Un, documentModelTestFileTemplate as Ut, getInitialStates as V, licenseTemplate as Vn, makeOperationsImports as Vt, getDefaultProjectOptions as W, legacyIndexHtmlTemplate as Wn, documentModelSrcUtilsTemplate as Wt, getProperyAssignmentByName as X, oxlintConfigTemplate as Xn, documentModelGenTypesTemplate as Xt, getObjectProperty as Y, oxfmtConfigTemplate as Yn, documentModelGenUtilsTemplate as Yt, getStringArrayPropertyElements as Z, editorsIndexTemplate as Zn, documentModelSchemaIndexTemplate as Zt, scalarsValidation as _, documentModelDocumentSchemaFileTemplate as _n, appDriveContentsFileTemplate as _r, parseArgs as _t, getOrCreateManifestFile as a, getDocumentModelDirName as an, connectEntrypointTemplate as ar, getOrCreateSourceFile as at, getCommandsHelpInfo as b, documentModelGenActionsFileTemplate as bn, customSubgraphSchemaTemplate as bt, operationHasEmptyInput as c, getEditorVariableNames as cn, agentsTemplate as cr, getProcessorMetadata as ct, generateDocumentModelZodSchemas as d, getActionInputName as dn, driveExplorerNavigationBreadcrumbsFileTemplate as dr, formatSafe as dt, documentModelOperationsModuleOperationsFileTemplate as en, documentModelsIndexTemplate as er, loadDocumentModelInDir as et, generateTypesAndZodSchemasFromGraphql as f, getActionInputTypeNames as fn, folderTreeFileTemplate as fr, formatSourceFileWithPrettier as ft, scalars as g, documentModelDocumentTypeTemplate as gn, driveExplorerFileTemplate as gr, configSpec as gt, getMockOverrideFieldNames as h, documentModelGenIndexFileTemplate as hn, emptyStateFileTemplate as hr, documentModelDocumentTypeMetadata as ht, createOrUpdateManifest as i, getModuleExportType as in, dockerfileTemplate as ir, getOrCreateDirectory as it, writeGeneratedProjectRootFiles as j, ManifestTemplate as jn, analyticsProcessorTemplate as jt, writeGeneratedEditorsFiles as k, styleTemplate as kn, processorsFactoryTemplate as kt, operationHasInput as l, getLatestDocumentModelSpec as ln, appEditorFileTemplate as lr, getAppMetadata as lt, getInputFieldNames as m, getActionTypeName as mn, appFilesFileTemplate as mr, getDocumentTypeMetadata as mt, tsMorphGenerateSubgraph as n, documentModelOperationsModuleCreatorsFileTemplate as nn, switchboardEntrypointTemplate as nr, buildStringLiteral as nt, pruneManifestSection as o, getDocumentModelSpecByVersionNumber as on, cursorMcpTemplate as or, getPreviousVersionSourceFile as ot, getDateLikeFieldNames as p, getActionType as pn, appFoldersFileTemplate as pr, runOxfmt as pt, getBooleanPropertyValue as q, syncAndPublishWorkflowTemplate as qn, documentModelIndexTemplate as qt, tsMorphGenerateProcessor as r, documentModelOperationModuleActionsFileTemplate as rn, nginxConfTemplate as rr, ensureDirectoriesExist as rt, makeModulesIndexFile as s, getDocumentModelVariableNames as sn, claudeSettingsLocalTemplate as sr, getSubgraphMetadata as st, makeSubgraphsIndexFile as t, documentModelOperationsModuleErrorFileTemplate as tn, documentModelsTemplate as tr, buildObjectLiteral as tt, tsMorphGenerateDocumentModel as u, getLatestDocumentModelSpecVersionNumber as un, appConfigFileTemplate as ur, getEditorMetadata as ut, tsMorphGenerateDocumentEditor as v, documentModelGenCreatorsFileTemplate as vn, createDocumentFileTemplate as vr, parseConfig as vt, applyProjectCustomizations as w, docsFromCliHelpTemplate as wn, relationalDbProcessorTemplate as wt, makeCliDocsFromHelp as x, documentModelRootActionsFileTemplate as xn, subgraphLibFileTemplate as xt, getCommandHelpInfo as y, documentModelGenControllerFileTemplate as yn, customSubgraphResolversTemplate as yt, validateDocumentModelState as z, mcpTemplate as zn, documentModelOperationsModuleTestFileTemplate as zt };
8722
8809
 
8723
- //# sourceMappingURL=file-builders-DaV8C_6p.mjs.map
8810
+ //# sourceMappingURL=file-builders-BBNHqY4N.mjs.map