@palantir/pack.document-schema.model-types 0.11.0 → 0.13.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 -1
- package/.turbo/turbo-transpileCjs.log +1 -1
- package/.turbo/turbo-transpileEsm.log +1 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +39 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +65 -71
- package/build/esm/index.js.map +1 -1
- package/build/types/index.d.ts +0 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types/ActivityEvent.d.ts +1 -0
- package/build/types/types/ActivityEvent.d.ts.map +1 -1
- package/build/types/types/DocumentMetadata.d.ts +2 -3
- package/build/types/types/DocumentMetadata.d.ts.map +1 -1
- package/build/types/types/DocumentRef.d.ts +40 -7
- package/build/types/types/DocumentRef.d.ts.map +1 -1
- package/build/types/types/Model.d.ts +1 -0
- package/build/types/types/Model.d.ts.map +1 -1
- package/build/types/types/PresenceEvent.d.ts +1 -0
- package/build/types/types/PresenceEvent.d.ts.map +1 -1
- package/build/types/types/RecordCollectionRef.d.ts +4 -15
- package/build/types/types/RecordCollectionRef.d.ts.map +1 -1
- package/build/types/types/RecordRef.d.ts +8 -32
- package/build/types/types/RecordRef.d.ts.map +1 -1
- package/build/types/types/UpgradeLens.d.ts +5 -6
- package/build/types/types/UpgradeLens.d.ts.map +1 -1
- package/build/types/utils/ActivityEvents.d.ts +6 -2
- package/build/types/utils/ActivityEvents.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/types/ActivityEvent.ts +1 -0
- package/src/types/DocumentMetadata.ts +2 -3
- package/src/types/DocumentRef.ts +47 -9
- package/src/types/Model.ts +1 -0
- package/src/types/PresenceEvent.ts +1 -0
- package/src/types/RecordCollectionRef.ts +4 -15
- package/src/types/RecordRef.ts +8 -34
- package/src/types/UpgradeLens.ts +5 -7
- package/src/utils/ActivityEvents.ts +6 -2
- package/build/types/types/JsonValue.d.ts +0 -8
- package/build/types/types/JsonValue.d.ts.map +0 -1
- package/src/types/JsonValue.ts +0 -28
package/src/types/Model.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import type { DocumentRef } from "./DocumentRef.js";
|
|
18
|
-
import type { Model
|
|
18
|
+
import type { Model } from "./Model.js";
|
|
19
19
|
import type { RecordId, RecordRef } from "./RecordRef.js";
|
|
20
20
|
|
|
21
21
|
export const RecordCollectionRefBrand: unique symbol = Symbol(
|
|
@@ -33,6 +33,9 @@ export interface RecordCollectionRef<M extends Model = Model> {
|
|
|
33
33
|
/**
|
|
34
34
|
* Delete a record from the collection (and the document).
|
|
35
35
|
*
|
|
36
|
+
* Version-agnostic: deletion needs only the record's identity, not its
|
|
37
|
+
* payload shape, so this is safe to call without narrowing to a version.
|
|
38
|
+
*
|
|
36
39
|
* @param id - The ID of the record to delete.
|
|
37
40
|
* @returns A promise that resolves when the record is deleted.
|
|
38
41
|
*/
|
|
@@ -53,20 +56,6 @@ export interface RecordCollectionRef<M extends Model = Model> {
|
|
|
53
56
|
* @returns True if the record exists, false otherwise.
|
|
54
57
|
*/
|
|
55
58
|
has(id: RecordId): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Set the data for a record in the collection (creating it if it doesn't exist).
|
|
58
|
-
*
|
|
59
|
-
* @param id - The ID of the record to set.
|
|
60
|
-
* @param state - The data to set for the record.
|
|
61
|
-
* @returns A promise that resolves when the record is set.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```ts
|
|
65
|
-
* const recordCollection = docRef.getRecords(MyModel);
|
|
66
|
-
* await recordCollection.set("record-id", { field: "value" });
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
set(id: RecordId, state: ModelData<M>): Promise<void>;
|
|
70
59
|
readonly size: number;
|
|
71
60
|
|
|
72
61
|
[Symbol.iterator](): Iterator<RecordRef<M>>;
|
package/src/types/RecordRef.ts
CHANGED
|
@@ -39,9 +39,10 @@ export const RecordRefBrand: unique symbol = Symbol("pack:RecordRef");
|
|
|
39
39
|
*
|
|
40
40
|
* const docRef = app.getDocRef<DocumentSchema>(someDocumentId);
|
|
41
41
|
*
|
|
42
|
-
*
|
|
42
|
+
* // Create a record via the version-narrowed setRecord on DocumentRef.
|
|
43
|
+
* await docRef.setRecord(MyModel, "my-record-id", { myFieldName: "some value", foo: 42 });
|
|
43
44
|
*
|
|
44
|
-
* //
|
|
45
|
+
* // Then get the ref back.
|
|
45
46
|
* const recordRef = docRef.getRecords(MyModel).get("my-record-id");
|
|
46
47
|
*/
|
|
47
48
|
export interface RecordRef<M extends Model = Model> {
|
|
@@ -69,8 +70,8 @@ export interface RecordRef<M extends Model = Model> {
|
|
|
69
70
|
* console.log("Record changed:", newSnapshot);
|
|
70
71
|
* });
|
|
71
72
|
*
|
|
72
|
-
* // Submit a change
|
|
73
|
-
*
|
|
73
|
+
* // Submit a change via the version-narrowed updateRecord on DocumentRef.
|
|
74
|
+
* await docRef.updateRecord(recordRef, { myFieldName: "new value" });
|
|
74
75
|
* ```
|
|
75
76
|
*/
|
|
76
77
|
onChange(callback: (snapshot: ModelData<M>, recordRef: RecordRef<M>) => void): Unsubscribe;
|
|
@@ -96,6 +97,9 @@ export interface RecordRef<M extends Model = Model> {
|
|
|
96
97
|
/**
|
|
97
98
|
* Delete the record from the document.
|
|
98
99
|
*
|
|
100
|
+
* Version-agnostic: deletion needs only the record's identity, not its
|
|
101
|
+
* payload shape, so this is safe to call without narrowing to a version.
|
|
102
|
+
*
|
|
99
103
|
* @returns An ignorable promise that resolves when the record is deleted.
|
|
100
104
|
*
|
|
101
105
|
* @example
|
|
@@ -104,34 +108,4 @@ export interface RecordRef<M extends Model = Model> {
|
|
|
104
108
|
* ```
|
|
105
109
|
*/
|
|
106
110
|
delete(): Promise<void>;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Set the data for the record (creating it if it doesn't exist).
|
|
110
|
-
*
|
|
111
|
-
* @see {onChange} to subscribe to changes to the record.
|
|
112
|
-
*
|
|
113
|
-
* @param record - The plain object data to set for the record, corresponding to the model's schema.
|
|
114
|
-
* @returns An ignorable promise that resolves when the record is published.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* await recordRef.set({ field: "value" });
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
set(record: ModelData<M>): Promise<void>;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Update specific fields of the record.
|
|
125
|
-
*
|
|
126
|
-
* @see {onChange} to subscribe to changes to the record.
|
|
127
|
-
*
|
|
128
|
-
* @param partialRecord - A partial plain object with the fields to update.
|
|
129
|
-
* @returns An ignorable promise that resolves when the record is published.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* await recordRef.update({ field: "new value" });
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
update(record: Partial<ModelData<M>>): Promise<void>;
|
|
137
111
|
}
|
package/src/types/UpgradeLens.ts
CHANGED
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import type { JsonValue } from "./JsonValue.js";
|
|
18
|
-
|
|
19
17
|
/** Type descriptor for a field, enabling recursive lens application. */
|
|
20
18
|
export type FieldTypeDescriptor =
|
|
21
19
|
| { kind: "primitive" }
|
|
@@ -26,17 +24,17 @@ export type FieldTypeDescriptor =
|
|
|
26
24
|
|
|
27
25
|
export interface FieldLensDef {
|
|
28
26
|
/**
|
|
29
|
-
* Source field names. When empty, the field is additive —
|
|
30
|
-
*
|
|
27
|
+
* Source field names. When empty, the field is additive — the upgrade fn
|
|
28
|
+
* receives `{}` and returns a value of the field's type. Either way, the
|
|
29
|
+
* runtime looks up an entry in `UpgradeFns` at this `(modelName, version,
|
|
30
|
+
* fieldName)` and calls it.
|
|
31
31
|
*/
|
|
32
32
|
derivedFrom: string[];
|
|
33
|
-
/** Literal JSON only — validated at schema build time. Used when no source data exists. */
|
|
34
|
-
default?: JsonValue;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
export interface FieldDef {
|
|
38
36
|
type: FieldTypeDescriptor;
|
|
39
|
-
|
|
37
|
+
addedInVersion?: number;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
export interface UpgradeStepDef {
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
ActivityEventDataUnknown,
|
|
21
21
|
} from "../types/ActivityEvent.js";
|
|
22
22
|
import { ActivityEventDataType } from "../types/ActivityEvent.js";
|
|
23
|
-
import type { EditDescription, Model
|
|
23
|
+
import type { EditDescription, Model } from "../types/Model.js";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Creates an edit description to describe an edit for activity purposes, for use with docRef.withTransaction.
|
|
@@ -39,7 +39,11 @@ import type { EditDescription, Model, ModelData } from "../types/Model.js";
|
|
|
39
39
|
* }));
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Narrow the document ref by version and use
|
|
44
|
+
* `doc.describeEdit(model, data)` instead.
|
|
45
|
+
*/
|
|
46
|
+
export function describeEdit<M extends Model>(model: M, data: never): EditDescription<M> {
|
|
43
47
|
return {
|
|
44
48
|
data,
|
|
45
49
|
model,
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;AAqBA,YAAY,+CAKR,cACA;gBAAiB","names":[],"sources":["../../../src/types/JsonValue.ts"],"version":3,"file":"JsonValue.d.ts"}
|
package/src/types/JsonValue.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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 };
|