@palantir/pack.document-schema.model-types 0.7.0 → 0.8.0

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 lint /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 lint /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > eslint ./src && dprint check --config $(find-up dprint.json) --allow-no-files
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 transpileBrowser /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 transpileBrowser /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > monorepo-transpile -f esm -m bundle -t browser
4
4
 
5
5
  [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 transpileCjs /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 transpileCjs /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > monorepo-transpile -f cjs -m bundle -t node
4
4
 
5
5
  [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 transpileEsm /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 transpileEsm /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > monorepo-transpile -f esm -m bundle -t node
4
4
 
5
5
  [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 transpileTypes /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 transpileTypes /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > monorepo-transpile -f esm -m types -t node
4
4
 
5
5
  👍
@@ -1,4 +1,4 @@
1
1
 
2
- > @palantir/pack.document-schema.model-types@0.7.0 typecheck /home/runner/work/pack/pack/packages/document-schema/model-types
2
+ > @palantir/pack.document-schema.model-types@0.8.0 typecheck /home/runner/work/pack/pack/packages/document-schema/model-types
3
3
  > tsc --noEmit --emitDeclarationOnly false
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @palantir/pack.document-schema.model-types
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2b00422: Add 'gen-types' command, along with scope, metadata and manifest generators
8
+ - 222e157: Wire in lens upgrade registry to reads in the yjs layer
9
+ - ad7a355: Add UpgradeLens utilities
10
+ - 792a1b0: Add new 'gen-types' command, direct from TS schema to Versioned SDK Types.
11
+
3
12
  ## 0.7.0
4
13
 
5
14
  ### Minor Changes
@@ -35,6 +35,12 @@ interface DocumentMetadata {
35
35
  readonly name: string;
36
36
  readonly operations?: readonly DocumentOperation[];
37
37
  readonly ontologyRid: string;
38
+ /**
39
+ * The schema version this document is currently operating at.
40
+ * All connected clients must read and write at this version.
41
+ * Set by the backend; only increases (one-way ratchet).
42
+ */
43
+ readonly schemaVersion?: number;
38
44
  readonly security: DocumentSecurity;
39
45
  readonly updatedBy?: string;
40
46
  readonly updatedTime?: string;
@@ -222,6 +228,63 @@ interface ActivityEvent {
222
228
  readonly isRead: boolean;
223
229
  }
224
230
 
231
+ /** Type descriptor for a field, enabling recursive lens application. */
232
+ type FieldTypeDescriptor = {
233
+ kind: "primitive";
234
+ } | {
235
+ kind: "modelRef";
236
+ model: string;
237
+ } | {
238
+ kind: "array";
239
+ element: FieldTypeDescriptor;
240
+ } | {
241
+ kind: "map";
242
+ value: FieldTypeDescriptor;
243
+ } | {
244
+ kind: "optional";
245
+ inner: FieldTypeDescriptor;
246
+ };
247
+ interface FieldLensDef {
248
+ /**
249
+ * Source field names. `forward` receives only these fields, not the full record.
250
+ * When empty, the field is additive — only `default` applies and `forward` is never called.
251
+ */
252
+ derivedFrom: string[];
253
+ forward: (oldFields: Record<string, unknown>) => unknown;
254
+ default?: unknown;
255
+ }
256
+ interface FieldDef {
257
+ type: FieldTypeDescriptor;
258
+ default?: unknown;
259
+ }
260
+ interface UpgradeStepDef {
261
+ name: string;
262
+ addedInVersion: number;
263
+ fields: Record<string, FieldLensDef>;
264
+ removedFields?: string[];
265
+ }
266
+ interface UpgradeRegistry<ModelName extends string = string> {
267
+ modelName: ModelName;
268
+ /** All fields in the current schema (not just upgraded ones). Drives recursive lens application on nested types. */
269
+ allFields: Record<string, FieldDef>;
270
+ /** Must be in version order — the lens walks them sequentially. */
271
+ steps: UpgradeStepDef[];
272
+ }
273
+ /**
274
+ * Upgrade registry for union models. Instead of having its own fields/steps,
275
+ * a union delegates to the variant's UpgradeRegistry based on the discriminant
276
+ * value in the data.
277
+ */
278
+ interface UnionUpgradeRegistry<ModelName extends string = string> {
279
+ modelName: ModelName;
280
+ /** The field name used to discriminate between variants. */
281
+ discriminant: string;
282
+ /** Maps discriminant values to variant model names in the UpgradeRegistryMap. */
283
+ variants: Record<string, string>;
284
+ }
285
+ type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
286
+ type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;
287
+
225
288
  /**
226
289
  * The base type for an application sdk's generated document schema.
227
290
  */
@@ -238,6 +301,8 @@ type DocumentState<S extends DocumentSchema> = {
238
301
  };
239
302
  interface DocumentSchemaMetadata {
240
303
  readonly version: number;
304
+ readonly minSupportedVersion?: number;
305
+ readonly upgrades?: UpgradeRegistryMap;
241
306
  }
242
307
 
243
308
  declare const PresenceEventDataType: {
@@ -869,4 +934,4 @@ declare namespace PresenceEvents {
869
934
  export { PresenceEvents_isArrived as isArrived, PresenceEvents_isCustom as isCustom, PresenceEvents_isDeparted as isDeparted, PresenceEvents_isUnknown as isUnknown };
870
935
  }
871
936
 
872
- export { type ActivityEvent, type ActivityEventData, type ActivityEventDataCustom, type ActivityEventDataDocumentCreate, type ActivityEventDataDocumentDescriptionUpdate, type ActivityEventDataDocumentDiscretionarySecurityUpdate, type ActivityEventDataDocumentMandatorySecurityUpdate, type ActivityEventDataDocumentRename, ActivityEventDataType, type ActivityEventDataUnknown, type ActivityEventId, ActivityEvents, type DiscretionaryPrincipal, type DiscretionaryPrincipal_All, type DiscretionaryPrincipal_GroupId, type DiscretionaryPrincipal_UserId, type DocumentId, type DocumentMetadata, type DocumentOperation, type DocumentRef, DocumentRefBrand, type DocumentSchema, type DocumentSchemaMetadata, type DocumentSecurity, type DocumentSecurityDiscretionary, type DocumentSecurityMandatory, type DocumentState, type EditDescription, ExternalRefType, type MediaId, type MediaRef, MediaRefBrand, Metadata, type Model, type ModelData, type ModelMetadata, type ObjectId, type ObjectRef, ObjectRefBrand, type PresenceEvent, type PresenceEventData, type PresenceEventDataArrived, type PresenceEventDataCustom, type PresenceEventDataDeparted, PresenceEventDataType, type PresenceEventDataUnknown, PresenceEvents, type PresencePublishOptions, type PresenceSubscriptionOptions, type RecordCollectionRef, RecordCollectionRefBrand, type RecordId, type RecordModel, type RecordRef, RecordRefBrand, type UnionModel, type Unsubscribe, type UserId, type UserRef, UserRefBrand, type WithMetadata, getMetadata, hasMetadata };
937
+ export { type ActivityEvent, type ActivityEventData, type ActivityEventDataCustom, type ActivityEventDataDocumentCreate, type ActivityEventDataDocumentDescriptionUpdate, type ActivityEventDataDocumentDiscretionarySecurityUpdate, type ActivityEventDataDocumentMandatorySecurityUpdate, type ActivityEventDataDocumentRename, ActivityEventDataType, type ActivityEventDataUnknown, type ActivityEventId, ActivityEvents, type DiscretionaryPrincipal, type DiscretionaryPrincipal_All, type DiscretionaryPrincipal_GroupId, type DiscretionaryPrincipal_UserId, type DocumentId, type DocumentMetadata, type DocumentOperation, type DocumentRef, DocumentRefBrand, type DocumentSchema, type DocumentSchemaMetadata, type DocumentSecurity, type DocumentSecurityDiscretionary, type DocumentSecurityMandatory, type DocumentState, type EditDescription, ExternalRefType, type FieldDef, type FieldLensDef, type FieldTypeDescriptor, type MediaId, type MediaRef, MediaRefBrand, Metadata, type Model, type ModelData, type ModelMetadata, type ObjectId, type ObjectRef, ObjectRefBrand, type PresenceEvent, type PresenceEventData, type PresenceEventDataArrived, type PresenceEventDataCustom, type PresenceEventDataDeparted, PresenceEventDataType, type PresenceEventDataUnknown, PresenceEvents, type PresencePublishOptions, type PresenceSubscriptionOptions, type RecordCollectionRef, RecordCollectionRefBrand, type RecordId, type RecordModel, type RecordRef, RecordRefBrand, type UnionModel, type UnionUpgradeRegistry, type Unsubscribe, type UpgradeRegistry, type UpgradeRegistryEntry, type UpgradeRegistryMap, type UpgradeStepDef, type UserId, type UserRef, UserRefBrand, type WithMetadata, getMetadata, hasMetadata };
@@ -19,6 +19,7 @@ export type { RecordCollectionRef } from "./types/RecordCollectionRef.js";
19
19
  export { RecordRefBrand } from "./types/RecordRef.js";
20
20
  export type { RecordId, RecordRef } from "./types/RecordRef.js";
21
21
  export type { Unsubscribe } from "./types/Unsubscribe.js";
22
+ export type { FieldDef, FieldLensDef, FieldTypeDescriptor, UnionUpgradeRegistry, UpgradeRegistry, UpgradeRegistryEntry, UpgradeRegistryMap, UpgradeStepDef } from "./types/UpgradeLens.js";
22
23
  export { UserRefBrand } from "./types/UserRef.js";
23
24
  export type { UserId, UserRef } from "./types/UserRef.js";
24
25
  export * as ActivityEvents from "./utils/ActivityEvents.js";
@@ -1 +1 @@
1
- {"mappings":"AAgBA,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,yBACA,iCACA,4CACA,sDACA,kDACA,iCACA,0BACA,uBACK;AACP,cACE,wBACA,4BACA,gCACA,+BACA,kBACA,mBACA,kBACA,+BACA,iCACK;AACP,SAAS,wBAAwB;AACjC,cACE,YACA,aACA,wBACA,mCACK;AACP,cACE,gBACA,wBACA,qBACK;AACP,SAAS,qBAAqB;AAC9B,cAAc,SAAS,gBAAgB;AACvC,SAAS,aAAa,aAAa,gBAAgB;AACnD,cAAc,oBAAoB;AAClC,SAAS,uBAAuB;AAChC,cACE,iBACA,OACA,WACA,eACA,aACA,kBACK;AACP,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,0BACA,yBACA,2BACA,gCACK;AACP,SAAS,gCAAgC;AACzC,cAAc,2BAA2B;AACzC,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,cAAc,mBAAmB;AACjC,SAAS,oBAAoB;AAC7B,cAAc,QAAQ,eAAe;AACrC,YAAY,oBAAoB;AAChC,YAAY,oBAAoB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
1
+ {"mappings":"AAgBA,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,yBACA,iCACA,4CACA,sDACA,kDACA,iCACA,0BACA,uBACK;AACP,cACE,wBACA,4BACA,gCACA,+BACA,kBACA,mBACA,kBACA,+BACA,iCACK;AACP,SAAS,wBAAwB;AACjC,cACE,YACA,aACA,wBACA,mCACK;AACP,cACE,gBACA,wBACA,qBACK;AACP,SAAS,qBAAqB;AAC9B,cAAc,SAAS,gBAAgB;AACvC,SAAS,aAAa,aAAa,gBAAgB;AACnD,cAAc,oBAAoB;AAClC,SAAS,uBAAuB;AAChC,cACE,iBACA,OACA,WACA,eACA,aACA,kBACK;AACP,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,SAAS,6BAA6B;AACtC,cACE,eACA,mBACA,0BACA,yBACA,2BACA,gCACK;AACP,SAAS,gCAAgC;AACzC,cAAc,2BAA2B;AACzC,SAAS,sBAAsB;AAC/B,cAAc,UAAU,iBAAiB;AACzC,cAAc,mBAAmB;AACjC,cACE,UACA,cACA,qBACA,sBACA,iBACA,sBACA,oBACA,sBACK;AACP,SAAS,oBAAoB;AAC7B,cAAc,QAAQ,eAAe;AACrC,YAAY,oBAAoB;AAChC,YAAY,oBAAoB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
@@ -32,6 +32,12 @@ export interface DocumentMetadata {
32
32
  readonly name: string;
33
33
  readonly operations?: readonly DocumentOperation[];
34
34
  readonly ontologyRid: string;
35
+ /**
36
+ * The schema version this document is currently operating at.
37
+ * All connected clients must read and write at this version.
38
+ * Set by the backend; only increases (one-way ratchet).
39
+ */
40
+ readonly schemaVersion?: number;
35
41
  readonly security: DocumentSecurity;
36
42
  readonly updatedBy?: string;
37
43
  readonly updatedTime?: string;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,iBAAiB,2BAA2B;CAC1C,QAAQ;;AAEV,iBAAiB,8BAA8B;CAC7C,QAAQ;CACR;;AAEF,iBAAiB,+BAA+B;CAC9C;CACA,QAAQ;;AAGV,YAAY,yBACR,6BACA,iCACA;AAEJ,iBAAiB,8BAA8B;UACpC,mBAAmB;UACnB,kBAAkB;UAClB,mBAAmB;;AAG9B,iBAAiB,0BAA0B;UAChC;UACA;;AAGX,iBAAiB,iBAAiB;UACvB,eAAe;UACf,WAAW;;AAGtB,YAAY,oBAAoB,SAAS,SAAS,QAAQ;AAE1D,iBAAiB,iBAAiB;UACvB;UACA;UACA;UACA;UACA;UACA,sBAAsB;UACtB;UACA,UAAU;UACV;UACA","names":[],"sources":["../../../src/types/DocumentMetadata.ts"],"version":3,"file":"DocumentMetadata.d.ts"}
1
+ {"mappings":"AAgBA,iBAAiB,2BAA2B;CAC1C,QAAQ;;AAEV,iBAAiB,8BAA8B;CAC7C,QAAQ;CACR;;AAEF,iBAAiB,+BAA+B;CAC9C;CACA,QAAQ;;AAGV,YAAY,yBACR,6BACA,iCACA;AAEJ,iBAAiB,8BAA8B;UACpC,mBAAmB;UACnB,kBAAkB;UAClB,mBAAmB;;AAG9B,iBAAiB,0BAA0B;UAChC;UACA;;AAGX,iBAAiB,iBAAiB;UACvB,eAAe;UACf,WAAW;;AAGtB,YAAY,oBAAoB,SAAS,SAAS,QAAQ;AAE1D,iBAAiB,iBAAiB;UACvB;UACA;UACA;UACA;UACA;UACA,sBAAsB;UACtB;;;;;;UAMA;UACA,UAAU;UACV;UACA","names":[],"sources":["../../../src/types/DocumentMetadata.ts"],"version":3,"file":"DocumentMetadata.d.ts"}
@@ -1,5 +1,6 @@
1
1
  import type { WithMetadata } from "./Metadata.js";
2
2
  import type { Model, ModelData } from "./Model.js";
3
+ import type { UpgradeRegistryMap } from "./UpgradeLens.js";
3
4
  /**
4
5
  * The base type for an application sdk's generated document schema.
5
6
  */
@@ -14,4 +15,6 @@ export type DocumentState<S extends DocumentSchema> = { readonly [K in Exclude<k
14
15
  } };
15
16
  export interface DocumentSchemaMetadata {
16
17
  readonly version: number;
18
+ readonly minSupportedVersion?: number;
19
+ readonly upgrades?: UpgradeRegistryMap;
17
20
  }
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;;;;AAKtC,iBAAiB,uBAAuB,aAAa,wBAAwB;+BAC7C;;;;;AAMhC,YAAY,cAAc,UAAU,8BACxB,KAAK,cAAc,cAAa;yBAA0B,UAAU,EAAE;;AAGlF,iBAAiB,uBAAuB;UAC7B","names":[],"sources":["../../../src/types/DocumentSchema.ts"],"version":3,"file":"DocumentSchema.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;AACtC,cAAc,0BAA0B;;;;AAKxC,iBAAiB,uBAAuB,aAAa,wBAAwB;+BAC7C;;;;;AAMhC,YAAY,cAAc,UAAU,8BACxB,KAAK,cAAc,cAAa;yBAA0B,UAAU,EAAE;;AAGlF,iBAAiB,uBAAuB;UAC7B;UACA;UACA,WAAW","names":[],"sources":["../../../src/types/DocumentSchema.ts"],"version":3,"file":"DocumentSchema.d.ts"}
@@ -0,0 +1,56 @@
1
+ /** Type descriptor for a field, enabling recursive lens application. */
2
+ export type FieldTypeDescriptor = {
3
+ kind: "primitive";
4
+ } | {
5
+ kind: "modelRef";
6
+ model: string;
7
+ } | {
8
+ kind: "array";
9
+ element: FieldTypeDescriptor;
10
+ } | {
11
+ kind: "map";
12
+ value: FieldTypeDescriptor;
13
+ } | {
14
+ kind: "optional";
15
+ inner: FieldTypeDescriptor;
16
+ };
17
+ export interface FieldLensDef {
18
+ /**
19
+ * Source field names. `forward` receives only these fields, not the full record.
20
+ * When empty, the field is additive — only `default` applies and `forward` is never called.
21
+ */
22
+ derivedFrom: string[];
23
+ forward: (oldFields: Record<string, unknown>) => unknown;
24
+ default?: unknown;
25
+ }
26
+ export interface FieldDef {
27
+ type: FieldTypeDescriptor;
28
+ default?: unknown;
29
+ }
30
+ export interface UpgradeStepDef {
31
+ name: string;
32
+ addedInVersion: number;
33
+ fields: Record<string, FieldLensDef>;
34
+ removedFields?: string[];
35
+ }
36
+ export interface UpgradeRegistry<ModelName extends string = string> {
37
+ modelName: ModelName;
38
+ /** All fields in the current schema (not just upgraded ones). Drives recursive lens application on nested types. */
39
+ allFields: Record<string, FieldDef>;
40
+ /** Must be in version order — the lens walks them sequentially. */
41
+ steps: UpgradeStepDef[];
42
+ }
43
+ /**
44
+ * Upgrade registry for union models. Instead of having its own fields/steps,
45
+ * a union delegates to the variant's UpgradeRegistry based on the discriminant
46
+ * value in the data.
47
+ */
48
+ export interface UnionUpgradeRegistry<ModelName extends string = string> {
49
+ modelName: ModelName;
50
+ /** The field name used to discriminate between variants. */
51
+ discriminant: string;
52
+ /** Maps discriminant values to variant model names in the UpgradeRegistryMap. */
53
+ variants: Record<string, string>;
54
+ }
55
+ export type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
56
+ export type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;
@@ -0,0 +1 @@
1
+ {"mappings":";AAiBA,YAAY,sBACR;CAAE,MAAM;IACR;CAAE,MAAM;CAAY;IACpB;CAAE,MAAM;CAAS,SAAS;IAC1B;CAAE,MAAM;CAAO,OAAO;IACtB;CAAE,MAAM;CAAY,OAAO;;AAE/B,iBAAiB,aAAa;;;;;CAK5B;CACA,UAAU,WAAW;CACrB;;AAGF,iBAAiB,SAAS;CACxB,MAAM;CACN;;AAGF,iBAAiB,eAAe;CAC9B;CACA;CACA,QAAQ,eAAe;CACvB;;AAGF,iBAAiB,gBAAgB,mCAAmC;CAClE,WAAW;;CAEX,WAAW,eAAe;;CAE1B,OAAO;;;;;;;AAQT,iBAAiB,qBAAqB,mCAAmC;CACvE,WAAW;;CAEX;;CAEA,UAAU;;AAGZ,YAAY,uBAAuB,kBAAkB;AAErD,YAAY,qBAAqB,eAAe","names":[],"sources":["../../../src/types/UpgradeLens.ts"],"version":3,"file":"UpgradeLens.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palantir/pack.document-schema.model-types",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Minimal types supporting generated PACK schemas",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -79,6 +79,16 @@ export type { RecordCollectionRef } from "./types/RecordCollectionRef.js";
79
79
  export { RecordRefBrand } from "./types/RecordRef.js";
80
80
  export type { RecordId, RecordRef } from "./types/RecordRef.js";
81
81
  export type { Unsubscribe } from "./types/Unsubscribe.js";
82
+ export type {
83
+ FieldDef,
84
+ FieldLensDef,
85
+ FieldTypeDescriptor,
86
+ UnionUpgradeRegistry,
87
+ UpgradeRegistry,
88
+ UpgradeRegistryEntry,
89
+ UpgradeRegistryMap,
90
+ UpgradeStepDef,
91
+ } from "./types/UpgradeLens.js";
82
92
  export { UserRefBrand } from "./types/UserRef.js";
83
93
  export type { UserId, UserRef } from "./types/UserRef.js";
84
94
  export * as ActivityEvents from "./utils/ActivityEvents.js";
@@ -57,6 +57,12 @@ export interface DocumentMetadata {
57
57
  readonly name: string;
58
58
  readonly operations?: readonly DocumentOperation[];
59
59
  readonly ontologyRid: string;
60
+ /**
61
+ * The schema version this document is currently operating at.
62
+ * All connected clients must read and write at this version.
63
+ * Set by the backend; only increases (one-way ratchet).
64
+ */
65
+ readonly schemaVersion?: number;
60
66
  readonly security: DocumentSecurity;
61
67
  readonly updatedBy?: string;
62
68
  readonly updatedTime?: string;
@@ -16,6 +16,7 @@
16
16
 
17
17
  import type { WithMetadata } from "./Metadata.js";
18
18
  import type { Model, ModelData } from "./Model.js";
19
+ import type { UpgradeRegistryMap } from "./UpgradeLens.js";
19
20
 
20
21
  /**
21
22
  * The base type for an application sdk's generated document schema.
@@ -33,4 +34,6 @@ export type DocumentState<S extends DocumentSchema> = {
33
34
 
34
35
  export interface DocumentSchemaMetadata {
35
36
  readonly version: number;
37
+ readonly minSupportedVersion?: number;
38
+ readonly upgrades?: UpgradeRegistryMap;
36
39
  }
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /** Type descriptor for a field, enabling recursive lens application. */
18
+ export type FieldTypeDescriptor =
19
+ | { kind: "primitive" }
20
+ | { kind: "modelRef"; model: string }
21
+ | { kind: "array"; element: FieldTypeDescriptor }
22
+ | { kind: "map"; value: FieldTypeDescriptor }
23
+ | { kind: "optional"; inner: FieldTypeDescriptor };
24
+
25
+ export interface FieldLensDef {
26
+ /**
27
+ * Source field names. `forward` receives only these fields, not the full record.
28
+ * When empty, the field is additive — only `default` applies and `forward` is never called.
29
+ */
30
+ derivedFrom: string[];
31
+ forward: (oldFields: Record<string, unknown>) => unknown;
32
+ default?: unknown;
33
+ }
34
+
35
+ export interface FieldDef {
36
+ type: FieldTypeDescriptor;
37
+ default?: unknown;
38
+ }
39
+
40
+ export interface UpgradeStepDef {
41
+ name: string;
42
+ addedInVersion: number;
43
+ fields: Record<string, FieldLensDef>;
44
+ removedFields?: string[];
45
+ }
46
+
47
+ export interface UpgradeRegistry<ModelName extends string = string> {
48
+ modelName: ModelName;
49
+ /** All fields in the current schema (not just upgraded ones). Drives recursive lens application on nested types. */
50
+ allFields: Record<string, FieldDef>;
51
+ /** Must be in version order — the lens walks them sequentially. */
52
+ steps: UpgradeStepDef[];
53
+ }
54
+
55
+ /**
56
+ * Upgrade registry for union models. Instead of having its own fields/steps,
57
+ * a union delegates to the variant's UpgradeRegistry based on the discriminant
58
+ * value in the data.
59
+ */
60
+ export interface UnionUpgradeRegistry<ModelName extends string = string> {
61
+ modelName: ModelName;
62
+ /** The field name used to discriminate between variants. */
63
+ discriminant: string;
64
+ /** Maps discriminant values to variant model names in the UpgradeRegistryMap. */
65
+ variants: Record<string, string>;
66
+ }
67
+
68
+ export type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
69
+
70
+ export type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;