@palantir/pack.document-schema.model-types 0.9.0 → 0.11.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.
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-transpileBrowser.log +1 -2
- package/.turbo/turbo-transpileCjs.log +1 -2
- package/.turbo/turbo-transpileEsm.log +1 -2
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +13 -0
- package/build/cjs/index.d.cts +36 -6
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types/DocumentSchema.d.ts +8 -1
- package/build/types/types/DocumentSchema.d.ts.map +1 -1
- package/build/types/types/JsonValue.d.ts +8 -0
- package/build/types/types/JsonValue.d.ts.map +1 -0
- package/build/types/types/UpgradeLens.d.ts +20 -5
- package/build/types/types/UpgradeLens.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/types/DocumentSchema.ts +8 -1
- package/src/types/JsonValue.ts +28 -0
- package/src/types/UpgradeLens.ts +25 -5
package/.turbo/turbo-lint.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.document-schema.model-types@0.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.document-schema.model-types@0.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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
|
-
[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`
|
|
6
5
|
👍
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.document-schema.model-types@0.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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
|
-
[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`
|
|
6
5
|
👍
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.document-schema.model-types@0.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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
|
-
[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`
|
|
6
5
|
👍
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @palantir/pack.document-schema.model-types@0.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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.
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.11.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,18 @@
|
|
|
1
1
|
# @palantir/pack.document-schema.model-types
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e540eba: Move upgrade forward functions out of the schema/IR into a typed UpgradeFns table that apps supply to the generated DocumentModel(...) factory at boot, eliminating Function.toString() source-splicing and enforcing exhaustive upgrade function coverage at compile time.
|
|
8
|
+
|
|
9
|
+
## 0.10.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [597bb0c]
|
|
14
|
+
- @palantir/pack.core@0.3.0
|
|
15
|
+
|
|
3
16
|
## 0.9.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -228,6 +228,15 @@ interface ActivityEvent {
|
|
|
228
228
|
readonly isRead: boolean;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Any value losslessly representable as JSON. Used to constrain literal defaults
|
|
233
|
+
* declared in the schema/IR — anything not expressible as JSON (functions,
|
|
234
|
+
* `Date`, `RegExp`, class instances, `undefined`) is rejected at the type level.
|
|
235
|
+
*/
|
|
236
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
237
|
+
[key: string]: JsonValue;
|
|
238
|
+
};
|
|
239
|
+
|
|
231
240
|
/** Type descriptor for a field, enabling recursive lens application. */
|
|
232
241
|
type FieldTypeDescriptor = {
|
|
233
242
|
kind: "primitive";
|
|
@@ -246,19 +255,19 @@ type FieldTypeDescriptor = {
|
|
|
246
255
|
};
|
|
247
256
|
interface FieldLensDef {
|
|
248
257
|
/**
|
|
249
|
-
* Source field names.
|
|
250
|
-
*
|
|
258
|
+
* Source field names. When empty, the field is additive — only `default` applies and no
|
|
259
|
+
* forward function is invoked.
|
|
251
260
|
*/
|
|
252
261
|
derivedFrom: string[];
|
|
253
|
-
|
|
254
|
-
default?:
|
|
262
|
+
/** Literal JSON only — validated at schema build time. Used when no source data exists. */
|
|
263
|
+
default?: JsonValue;
|
|
255
264
|
}
|
|
256
265
|
interface FieldDef {
|
|
257
266
|
type: FieldTypeDescriptor;
|
|
258
267
|
default?: unknown;
|
|
259
268
|
}
|
|
260
269
|
interface UpgradeStepDef {
|
|
261
|
-
|
|
270
|
+
/** Schema version this step upgrades to. Unique within a model's chain. */
|
|
262
271
|
addedInVersion: number;
|
|
263
272
|
fields: Record<string, FieldLensDef>;
|
|
264
273
|
removedFields?: string[];
|
|
@@ -284,6 +293,20 @@ interface UnionUpgradeRegistry<ModelName extends string = string> {
|
|
|
284
293
|
}
|
|
285
294
|
type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
|
|
286
295
|
type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;
|
|
296
|
+
/**
|
|
297
|
+
* Runtime-supplied collection of forward upgrade functions. The application
|
|
298
|
+
* passes a `DocumentUpgradeFns` value to the generated `DocumentModel(...)`
|
|
299
|
+
* factory at boot; the factory installs it on the schema's metadata under
|
|
300
|
+
* this loose shape: `fns[modelName][\`v${addedInVersion}\`][fieldName] -> fn`.
|
|
301
|
+
*
|
|
302
|
+
* The generated `DocumentUpgradeFns` interface is a precisely-typed refinement
|
|
303
|
+
* of this shape; both `BaseYjsDocumentService` and `applyReadLens` read from
|
|
304
|
+
* it via this loose type.
|
|
305
|
+
*
|
|
306
|
+
* Paired with `UpgradeRegistry`: the registry is the structural spec (WHEN to
|
|
307
|
+
* upgrade and from which fields), `UpgradeFns` provides the implementations.
|
|
308
|
+
*/
|
|
309
|
+
type UpgradeFns = Record<string, Record<string, Record<string, (oldFields: any) => any>>>;
|
|
287
310
|
|
|
288
311
|
/**
|
|
289
312
|
* The base type for an application sdk's generated document schema.
|
|
@@ -303,6 +326,13 @@ interface DocumentSchemaMetadata {
|
|
|
303
326
|
readonly version: number;
|
|
304
327
|
readonly minSupportedVersion?: number;
|
|
305
328
|
readonly upgrades?: UpgradeRegistryMap;
|
|
329
|
+
/**
|
|
330
|
+
* Typed forward functions, supplied by the app at boot via the generated
|
|
331
|
+
* `DocumentModel(...)` factory. Populated when the schema has any derived
|
|
332
|
+
* fields; absent for schemas that don't need any (single-version or purely
|
|
333
|
+
* additive across versions). Paired with `upgrades` (the structural spec).
|
|
334
|
+
*/
|
|
335
|
+
readonly upgradeFns?: UpgradeFns;
|
|
306
336
|
}
|
|
307
337
|
|
|
308
338
|
declare const PresenceEventDataType: {
|
|
@@ -934,4 +964,4 @@ declare namespace PresenceEvents {
|
|
|
934
964
|
export { PresenceEvents_isArrived as isArrived, PresenceEvents_isCustom as isCustom, PresenceEvents_isDeparted as isDeparted, PresenceEvents_isUnknown as isUnknown };
|
|
935
965
|
}
|
|
936
966
|
|
|
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 };
|
|
967
|
+
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 JsonValue, 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 UpgradeFns, type UpgradeRegistry, type UpgradeRegistryEntry, type UpgradeRegistryMap, type UpgradeStepDef, type UserId, type UserRef, UserRefBrand, type WithMetadata, getMetadata, hasMetadata };
|
package/build/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { DiscretionaryPrincipal, DiscretionaryPrincipal_All, DiscretionaryP
|
|
|
4
4
|
export { DocumentRefBrand } from "./types/DocumentRef.js";
|
|
5
5
|
export type { DocumentId, DocumentRef, PresencePublishOptions, PresenceSubscriptionOptions } from "./types/DocumentRef.js";
|
|
6
6
|
export type { DocumentSchema, DocumentSchemaMetadata, DocumentState } from "./types/DocumentSchema.js";
|
|
7
|
+
export type { JsonValue } from "./types/JsonValue.js";
|
|
7
8
|
export { MediaRefBrand } from "./types/MediaRef.js";
|
|
8
9
|
export type { MediaId, MediaRef } from "./types/MediaRef.js";
|
|
9
10
|
export { getMetadata, hasMetadata, Metadata } from "./types/Metadata.js";
|
|
@@ -19,7 +20,7 @@ export type { RecordCollectionRef } from "./types/RecordCollectionRef.js";
|
|
|
19
20
|
export { RecordRefBrand } from "./types/RecordRef.js";
|
|
20
21
|
export type { RecordId, RecordRef } from "./types/RecordRef.js";
|
|
21
22
|
export type { Unsubscribe } from "./types/Unsubscribe.js";
|
|
22
|
-
export type { FieldDef, FieldLensDef, FieldTypeDescriptor, UnionUpgradeRegistry, UpgradeRegistry, UpgradeRegistryEntry, UpgradeRegistryMap, UpgradeStepDef } from "./types/UpgradeLens.js";
|
|
23
|
+
export type { FieldDef, FieldLensDef, FieldTypeDescriptor, UnionUpgradeRegistry, UpgradeFns, UpgradeRegistry, UpgradeRegistryEntry, UpgradeRegistryMap, UpgradeStepDef } from "./types/UpgradeLens.js";
|
|
23
24
|
export { UserRefBrand } from "./types/UserRef.js";
|
|
24
25
|
export type { UserId, UserRef } from "./types/UserRef.js";
|
|
25
26
|
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,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"}
|
|
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,cAAc,iBAAiB;AAC/B,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,YACA,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"}
|
|
@@ -1,6 +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
|
+
import type { UpgradeFns, UpgradeRegistryMap } from "./UpgradeLens.js";
|
|
4
4
|
/**
|
|
5
5
|
* The base type for an application sdk's generated document schema.
|
|
6
6
|
*/
|
|
@@ -17,4 +17,11 @@ export interface DocumentSchemaMetadata {
|
|
|
17
17
|
readonly version: number;
|
|
18
18
|
readonly minSupportedVersion?: number;
|
|
19
19
|
readonly upgrades?: UpgradeRegistryMap;
|
|
20
|
+
/**
|
|
21
|
+
* Typed forward functions, supplied by the app at boot via the generated
|
|
22
|
+
* `DocumentModel(...)` factory. Populated when the schema has any derived
|
|
23
|
+
* fields; absent for schemas that don't need any (single-version or purely
|
|
24
|
+
* additive across versions). Paired with `upgrades` (the structural spec).
|
|
25
|
+
*/
|
|
26
|
+
readonly upgradeFns?: UpgradeFns;
|
|
20
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;AACtC,cAAc,0BAA0B;;;;
|
|
1
|
+
{"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;AACtC,cAAc,YAAY,0BAA0B;;;;AAKpD,iBAAiB,uBAAuB,aAAa,wBAAwB;+BAC7C;;;;;AAMhC,YAAY,cAAc,UAAU,8BACxB,KAAK,cAAc,cAAa;yBAA0B,UAAU,EAAE;;AAGlF,iBAAiB,uBAAuB;UAC7B;UACA;UACA,WAAW;;;;;;;UAOX,aAAa","names":[],"sources":["../../../src/types/DocumentSchema.ts"],"version":3,"file":"DocumentSchema.d.ts"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any value losslessly representable as JSON. Used to constrain literal defaults
|
|
3
|
+
* declared in the schema/IR — anything not expressible as JSON (functions,
|
|
4
|
+
* `Date`, `RegExp`, class instances, `undefined`) is rejected at the type level.
|
|
5
|
+
*/
|
|
6
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAqBA,YAAY,+CAKR,cACA;gBAAiB","names":[],"sources":["../../../src/types/JsonValue.ts"],"version":3,"file":"JsonValue.d.ts"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JsonValue } from "./JsonValue.js";
|
|
1
2
|
/** Type descriptor for a field, enabling recursive lens application. */
|
|
2
3
|
export type FieldTypeDescriptor = {
|
|
3
4
|
kind: "primitive";
|
|
@@ -16,19 +17,19 @@ export type FieldTypeDescriptor = {
|
|
|
16
17
|
};
|
|
17
18
|
export interface FieldLensDef {
|
|
18
19
|
/**
|
|
19
|
-
* Source field names.
|
|
20
|
-
*
|
|
20
|
+
* Source field names. When empty, the field is additive — only `default` applies and no
|
|
21
|
+
* forward function is invoked.
|
|
21
22
|
*/
|
|
22
23
|
derivedFrom: string[];
|
|
23
|
-
|
|
24
|
-
default?:
|
|
24
|
+
/** Literal JSON only — validated at schema build time. Used when no source data exists. */
|
|
25
|
+
default?: JsonValue;
|
|
25
26
|
}
|
|
26
27
|
export interface FieldDef {
|
|
27
28
|
type: FieldTypeDescriptor;
|
|
28
29
|
default?: unknown;
|
|
29
30
|
}
|
|
30
31
|
export interface UpgradeStepDef {
|
|
31
|
-
|
|
32
|
+
/** Schema version this step upgrades to. Unique within a model's chain. */
|
|
32
33
|
addedInVersion: number;
|
|
33
34
|
fields: Record<string, FieldLensDef>;
|
|
34
35
|
removedFields?: string[];
|
|
@@ -54,3 +55,17 @@ export interface UnionUpgradeRegistry<ModelName extends string = string> {
|
|
|
54
55
|
}
|
|
55
56
|
export type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
|
|
56
57
|
export type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;
|
|
58
|
+
/**
|
|
59
|
+
* Runtime-supplied collection of forward upgrade functions. The application
|
|
60
|
+
* passes a `DocumentUpgradeFns` value to the generated `DocumentModel(...)`
|
|
61
|
+
* factory at boot; the factory installs it on the schema's metadata under
|
|
62
|
+
* this loose shape: `fns[modelName][\`v${addedInVersion}\`][fieldName] -> fn`.
|
|
63
|
+
*
|
|
64
|
+
* The generated `DocumentUpgradeFns` interface is a precisely-typed refinement
|
|
65
|
+
* of this shape; both `BaseYjsDocumentService` and `applyReadLens` read from
|
|
66
|
+
* it via this loose type.
|
|
67
|
+
*
|
|
68
|
+
* Paired with `UpgradeRegistry`: the registry is the structural spec (WHEN to
|
|
69
|
+
* upgrade and from which fields), `UpgradeFns` provides the implementations.
|
|
70
|
+
*/
|
|
71
|
+
export type UpgradeFns = Record<string, Record<string, Record<string, (oldFields: any) => any>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAgBA,cAAc,iBAAiB;;AAG/B,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;;CAEA,UAAU;;AAGZ,iBAAiB,SAAS;CACxB,MAAM;CACN;;AAGF,iBAAiB,eAAe;;CAE9B;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;;;;;;;;;;;;;;AAehD,YAAY,aAAa,eAEvB,eAAe,gBAAgB","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.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Minimal types supporting generated PACK schemas",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@palantir/pack.core": "~0.
|
|
31
|
+
"@palantir/pack.core": "~0.3.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"zod": "^4.1.7"
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export type {
|
|
|
50
50
|
DocumentSchemaMetadata,
|
|
51
51
|
DocumentState,
|
|
52
52
|
} from "./types/DocumentSchema.js";
|
|
53
|
+
export type { JsonValue } from "./types/JsonValue.js";
|
|
53
54
|
export { MediaRefBrand } from "./types/MediaRef.js";
|
|
54
55
|
export type { MediaId, MediaRef } from "./types/MediaRef.js";
|
|
55
56
|
export { getMetadata, hasMetadata, Metadata } from "./types/Metadata.js";
|
|
@@ -84,6 +85,7 @@ export type {
|
|
|
84
85
|
FieldLensDef,
|
|
85
86
|
FieldTypeDescriptor,
|
|
86
87
|
UnionUpgradeRegistry,
|
|
88
|
+
UpgradeFns,
|
|
87
89
|
UpgradeRegistry,
|
|
88
90
|
UpgradeRegistryEntry,
|
|
89
91
|
UpgradeRegistryMap,
|
|
@@ -16,7 +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
|
+
import type { UpgradeFns, UpgradeRegistryMap } from "./UpgradeLens.js";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The base type for an application sdk's generated document schema.
|
|
@@ -36,4 +36,11 @@ export interface DocumentSchemaMetadata {
|
|
|
36
36
|
readonly version: number;
|
|
37
37
|
readonly minSupportedVersion?: number;
|
|
38
38
|
readonly upgrades?: UpgradeRegistryMap;
|
|
39
|
+
/**
|
|
40
|
+
* Typed forward functions, supplied by the app at boot via the generated
|
|
41
|
+
* `DocumentModel(...)` factory. Populated when the schema has any derived
|
|
42
|
+
* fields; absent for schemas that don't need any (single-version or purely
|
|
43
|
+
* additive across versions). Paired with `upgrades` (the structural spec).
|
|
44
|
+
*/
|
|
45
|
+
readonly upgradeFns?: UpgradeFns;
|
|
39
46
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Any value losslessly representable as JSON. Used to constrain literal defaults
|
|
19
|
+
* declared in the schema/IR — anything not expressible as JSON (functions,
|
|
20
|
+
* `Date`, `RegExp`, class instances, `undefined`) is rejected at the type level.
|
|
21
|
+
*/
|
|
22
|
+
export type JsonValue =
|
|
23
|
+
| string
|
|
24
|
+
| number
|
|
25
|
+
| boolean
|
|
26
|
+
| null
|
|
27
|
+
| JsonValue[]
|
|
28
|
+
| { [key: string]: JsonValue };
|
package/src/types/UpgradeLens.ts
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import type { JsonValue } from "./JsonValue.js";
|
|
18
|
+
|
|
17
19
|
/** Type descriptor for a field, enabling recursive lens application. */
|
|
18
20
|
export type FieldTypeDescriptor =
|
|
19
21
|
| { kind: "primitive" }
|
|
@@ -24,12 +26,12 @@ export type FieldTypeDescriptor =
|
|
|
24
26
|
|
|
25
27
|
export interface FieldLensDef {
|
|
26
28
|
/**
|
|
27
|
-
* Source field names.
|
|
28
|
-
*
|
|
29
|
+
* Source field names. When empty, the field is additive — only `default` applies and no
|
|
30
|
+
* forward function is invoked.
|
|
29
31
|
*/
|
|
30
32
|
derivedFrom: string[];
|
|
31
|
-
|
|
32
|
-
default?:
|
|
33
|
+
/** Literal JSON only — validated at schema build time. Used when no source data exists. */
|
|
34
|
+
default?: JsonValue;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export interface FieldDef {
|
|
@@ -38,7 +40,7 @@ export interface FieldDef {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export interface UpgradeStepDef {
|
|
41
|
-
|
|
43
|
+
/** Schema version this step upgrades to. Unique within a model's chain. */
|
|
42
44
|
addedInVersion: number;
|
|
43
45
|
fields: Record<string, FieldLensDef>;
|
|
44
46
|
removedFields?: string[];
|
|
@@ -68,3 +70,21 @@ export interface UnionUpgradeRegistry<ModelName extends string = string> {
|
|
|
68
70
|
export type UpgradeRegistryEntry = UpgradeRegistry | UnionUpgradeRegistry;
|
|
69
71
|
|
|
70
72
|
export type UpgradeRegistryMap = Record<string, UpgradeRegistryEntry>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Runtime-supplied collection of forward upgrade functions. The application
|
|
76
|
+
* passes a `DocumentUpgradeFns` value to the generated `DocumentModel(...)`
|
|
77
|
+
* factory at boot; the factory installs it on the schema's metadata under
|
|
78
|
+
* this loose shape: `fns[modelName][\`v${addedInVersion}\`][fieldName] -> fn`.
|
|
79
|
+
*
|
|
80
|
+
* The generated `DocumentUpgradeFns` interface is a precisely-typed refinement
|
|
81
|
+
* of this shape; both `BaseYjsDocumentService` and `applyReadLens` read from
|
|
82
|
+
* it via this loose type.
|
|
83
|
+
*
|
|
84
|
+
* Paired with `UpgradeRegistry`: the registry is the structural spec (WHEN to
|
|
85
|
+
* upgrade and from which fields), `UpgradeFns` provides the implementations.
|
|
86
|
+
*/
|
|
87
|
+
export type UpgradeFns = Record<
|
|
88
|
+
string,
|
|
89
|
+
Record<string, Record<string, (oldFields: any) => any>>
|
|
90
|
+
>;
|