@palantir/pack.document-schema.model-types 0.0.1-beta.1
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 +10 -0
- package/.turbo/turbo-transpileBrowser.log +5 -0
- package/.turbo/turbo-transpileCjs.log +5 -0
- package/.turbo/turbo-transpileEsm.log +5 -0
- package/.turbo/turbo-transpileTypes.log +5 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/LICENSE.txt +13 -0
- package/README.md +52 -0
- package/build/browser/index.js +13 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +16 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +35 -0
- package/build/esm/index.js +13 -0
- package/build/esm/index.js.map +1 -0
- package/build/types/index.d.ts +4 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/types/DocumentSchema.d.ts +11 -0
- package/build/types/types/DocumentSchema.d.ts.map +1 -0
- package/build/types/types/Metadata.d.ts +5 -0
- package/build/types/types/Metadata.d.ts.map +1 -0
- package/build/types/types/Model.d.ts +18 -0
- package/build/types/types/Model.d.ts.map +1 -0
- package/package.json +58 -0
- package/src/index.ts +24 -0
- package/src/types/DocumentSchema.ts +30 -0
- package/src/types/Metadata.ts +30 -0
- package/src/types/Model.ts +37 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mjs +26 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
> @palantir/pack.document-schema.model-types@0.0.1-beta.1 lint /home/runner/work/pack/pack/packages/document-schema/model-types
|
|
3
|
+
> eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files
|
|
4
|
+
|
|
5
|
+
Compiling https://plugins.dprint.dev/g-plane/markup_fmt-v0.23.1.wasm
|
|
6
|
+
Compiling https://plugins.dprint.dev/json-0.20.0.wasm
|
|
7
|
+
Compiling https://plugins.dprint.dev/g-plane/malva-v0.14.2.wasm
|
|
8
|
+
Compiling https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm
|
|
9
|
+
Compiling https://plugins.dprint.dev/typescript-0.95.10.wasm
|
|
10
|
+
Compiling https://plugins.dprint.dev/markdown-0.19.0.wasm
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Palantir Technologies, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @palantir/pack.document-schema.model-types
|
|
2
|
+
|
|
3
|
+
Minimal runtime types and interfaces supporting generated [PACK](https://github.com/palantir/pack) schemas, providing the foundational types for schema-generated models.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package contains the core runtime type definitions that generated schemas depend on. It provides minimal, lightweight interfaces for document schemas, models, and metadata that are used by generated code and runtime validation.
|
|
8
|
+
|
|
9
|
+
## Key Exports
|
|
10
|
+
|
|
11
|
+
### Core Types
|
|
12
|
+
|
|
13
|
+
- `Model<M, Z>` - Interface for schema-generated models with Zod validation
|
|
14
|
+
- `ModelData<M>` - Utility type to extract data type from a Model
|
|
15
|
+
- `ModelMetadata` - Metadata interface for models (name, documentation, etc.)
|
|
16
|
+
|
|
17
|
+
### Document Schema Types
|
|
18
|
+
|
|
19
|
+
- `DocumentSchema` - Interface for complete document schema definitions
|
|
20
|
+
- `DocumentSchemaMetadata` - Metadata for document schemas
|
|
21
|
+
- `DocumentState` - Runtime state information for documents
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
This package is primarily used by generated code and other PACK packages. It's not typically imported directly by application code.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import type {
|
|
29
|
+
Model,
|
|
30
|
+
ModelData,
|
|
31
|
+
} from "@palantir/pack.document-schema.model-types";
|
|
32
|
+
import { getMetadata } from "@palantir/pack.document-schema.model-types";
|
|
33
|
+
|
|
34
|
+
// Example of how generated schemas use these types
|
|
35
|
+
interface UserModel extends Model<UserData, ZodUserSchema> {
|
|
36
|
+
readonly __type: UserData;
|
|
37
|
+
readonly zodSchema: ZodUserSchema;
|
|
38
|
+
readonly [Metadata]: {
|
|
39
|
+
name: "User";
|
|
40
|
+
// other metadata
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Extract the data type from a model
|
|
45
|
+
type UserData = ModelData<GeneratedUserModel>;
|
|
46
|
+
|
|
47
|
+
getMetadata(UserModel).name; // -> "User"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Dependencies
|
|
51
|
+
|
|
52
|
+
- `zod@v4` - For runtime schema inspection & validation
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/types/Metadata.ts
|
|
2
|
+
var Metadata = Symbol("@pack/document-schema/metadata");
|
|
3
|
+
function getMetadata(obj) {
|
|
4
|
+
const metadata = obj[Metadata];
|
|
5
|
+
if (metadata == null) {
|
|
6
|
+
throw new Error("Object does not have metadata");
|
|
7
|
+
}
|
|
8
|
+
return metadata;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { Metadata, getMetadata };
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/Metadata.ts"],"names":[],"mappings":";AAgBO,IAAM,QAAA,GAAW,OAAO,gCAAgC;AACxD,SAAS,YAAY,GAAA,EAAK;AAE/B,EAAA,MAAM,QAAA,GAAW,IAAI,QAAQ,CAAA;AAC7B,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,QAAA;AACT","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Metadata = Symbol(\"@pack/document-schema/metadata\");\nexport function getMetadata(obj) {\n // TS always treats symbol keys as optional\n const metadata = obj[Metadata];\n if (metadata == null) {\n throw new Error(\"Object does not have metadata\");\n }\n return metadata;\n}"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/Metadata.ts
|
|
4
|
+
var Metadata = Symbol("@pack/document-schema/metadata");
|
|
5
|
+
function getMetadata(obj) {
|
|
6
|
+
const metadata = obj[Metadata];
|
|
7
|
+
if (metadata == null) {
|
|
8
|
+
throw new Error("Object does not have metadata");
|
|
9
|
+
}
|
|
10
|
+
return metadata;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.Metadata = Metadata;
|
|
14
|
+
exports.getMetadata = getMetadata;
|
|
15
|
+
//# sourceMappingURL=index.cjs.map
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/Metadata.ts"],"names":[],"mappings":";;;AAgBO,IAAM,QAAA,GAAW,OAAO,gCAAgC;AACxD,SAAS,YAAY,GAAA,EAAK;AAE/B,EAAA,MAAM,QAAA,GAAW,IAAI,QAAQ,CAAA;AAC7B,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,QAAA;AACT","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Metadata = Symbol(\"@pack/document-schema/metadata\");\nexport function getMetadata(obj) {\n // TS always treats symbol keys as optional\n const metadata = obj[Metadata];\n if (metadata == null) {\n throw new Error(\"Object does not have metadata\");\n }\n return metadata;\n}"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const Metadata: symbol;
|
|
4
|
+
interface WithMetadata<T> {
|
|
5
|
+
readonly [Metadata]: T;
|
|
6
|
+
}
|
|
7
|
+
declare function getMetadata<T>(obj: WithMetadata<T>): T;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A Model defines the structure of a document record or union.
|
|
11
|
+
*
|
|
12
|
+
* It includes a zod schema for validation and type information.
|
|
13
|
+
*/
|
|
14
|
+
interface Model<T = unknown, Z extends ZodType<T> = ZodType<T>> extends WithMetadata<ModelMetadata> {
|
|
15
|
+
readonly __type: T;
|
|
16
|
+
readonly zodSchema: Readonly<Z>;
|
|
17
|
+
}
|
|
18
|
+
type ModelData<M extends Model> = M["__type"];
|
|
19
|
+
interface ModelMetadata {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface DocumentSchema extends WithMetadata<DocumentSchemaMetadata> {
|
|
24
|
+
readonly [modelName: string]: Model;
|
|
25
|
+
}
|
|
26
|
+
type DocumentState<S extends DocumentSchema> = {
|
|
27
|
+
readonly [K in Exclude<keyof S, symbol>]: {
|
|
28
|
+
readonly [key: string]: ModelData<S[K]>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
interface DocumentSchemaMetadata {
|
|
32
|
+
readonly version: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { type DocumentSchema, type DocumentSchemaMetadata, type DocumentState, Metadata, type Model, type ModelData, type ModelMetadata, type WithMetadata, getMetadata };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/types/Metadata.ts
|
|
2
|
+
var Metadata = Symbol("@pack/document-schema/metadata");
|
|
3
|
+
function getMetadata(obj) {
|
|
4
|
+
const metadata = obj[Metadata];
|
|
5
|
+
if (metadata == null) {
|
|
6
|
+
throw new Error("Object does not have metadata");
|
|
7
|
+
}
|
|
8
|
+
return metadata;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { Metadata, getMetadata };
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/Metadata.ts"],"names":[],"mappings":";AAgBO,IAAM,QAAA,GAAW,OAAO,gCAAgC;AACxD,SAAS,YAAY,GAAA,EAAK;AAE/B,EAAA,MAAM,QAAA,GAAW,IAAI,QAAQ,CAAA;AAC7B,EAAA,IAAI,YAAY,IAAA,EAAM;AACpB,IAAA,MAAM,IAAI,MAAM,+BAA+B,CAAA;AAAA,EACjD;AACA,EAAA,OAAO,QAAA;AACT","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Metadata = Symbol(\"@pack/document-schema/metadata\");\nexport function getMetadata(obj) {\n // TS always treats symbol keys as optional\n const metadata = obj[Metadata];\n if (metadata == null) {\n throw new Error(\"Object does not have metadata\");\n }\n return metadata;\n}"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { DocumentSchema, DocumentSchemaMetadata, DocumentState } from "./types/DocumentSchema.js";
|
|
2
|
+
export { getMetadata, Metadata } from "./types/Metadata.js";
|
|
3
|
+
export type { WithMetadata } from "./types/Metadata.js";
|
|
4
|
+
export type { Model, ModelData, ModelMetadata } from "./types/Model.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cACE,gBACA,wBACA,qBACK;AACP,SAAS,aAAa,gBAAgB;AACtC,cAAc,oBAAoB;AAClC,cAAc,OAAO,WAAW,qBAAqB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WithMetadata } from "./Metadata.js";
|
|
2
|
+
import type { Model, ModelData } from "./Model.js";
|
|
3
|
+
export interface DocumentSchema extends WithMetadata<DocumentSchemaMetadata> {
|
|
4
|
+
readonly [modelName: string]: Model;
|
|
5
|
+
}
|
|
6
|
+
export type DocumentState<S extends DocumentSchema> = { readonly [K in Exclude<keyof S, symbol>] : {
|
|
7
|
+
readonly [key: string]: ModelData<S[K]>;
|
|
8
|
+
} };
|
|
9
|
+
export interface DocumentSchemaMetadata {
|
|
10
|
+
readonly version: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,oBAAoB;AAClC,cAAc,OAAO,iBAAiB;AAEtC,iBAAiB,uBAAuB,aAAa,wBAAwB;+BAC7C;;AAGhC,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,OAAO,cAAMA;AAEb,iBAAiB,aAAa,GAAG;WACrB,WAAW;;AAGvB,OAAO,iBAAS,YAAY,GAAG,KAAK,aAAa,KAAK","names":["Metadata: symbol"],"sources":["../../../src/types/Metadata.ts"],"version":3,"file":"Metadata.d.ts"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
import type { WithMetadata } from "./Metadata.js";
|
|
3
|
+
/**
|
|
4
|
+
* A Model defines the structure of a document record or union.
|
|
5
|
+
*
|
|
6
|
+
* It includes a zod schema for validation and type information.
|
|
7
|
+
*/
|
|
8
|
+
export interface Model<
|
|
9
|
+
T = unknown,
|
|
10
|
+
Z extends ZodType<T> = ZodType<T>
|
|
11
|
+
> extends WithMetadata<ModelMetadata> {
|
|
12
|
+
readonly __type: T;
|
|
13
|
+
readonly zodSchema: Readonly<Z>;
|
|
14
|
+
}
|
|
15
|
+
export type ModelData<M extends Model> = M["__type"];
|
|
16
|
+
export interface ModelMetadata {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,eAAe;AAC7B,cAAc,oBAAoB;;;;;;AAQlC,iBAAiB;CAAM;CAAa,UAAU,QAAQ,KAAK,QAAQ;UACzD,aAAa,eACvB;UACW,QAAQ;UACR,WAAW,SAAS;;AAG/B,YAAY,UAAU,UAAU,SAAS,EAAE;AAE3C,iBAAiB,cAAc;UACpB","names":[],"sources":["../../../src/types/Model.ts"],"version":3,"file":"Model.d.ts"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@palantir/pack.document-schema.model-types",
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
|
+
"description": "Minimal types supporting generated PACK schemas",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/palantir/pack.git"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"browser": "./build/browser/index.js",
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./build/types/index.d.ts",
|
|
15
|
+
"default": "./build/esm/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": "./build/cjs/index.js",
|
|
18
|
+
"default": "./build/browser/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./*": {
|
|
21
|
+
"browser": "./build/browser/public/*.js",
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./build/types/public/*.d.ts",
|
|
24
|
+
"default": "./build/js/public/*.js"
|
|
25
|
+
},
|
|
26
|
+
"require": "./build/cjs/public/*.js",
|
|
27
|
+
"default": "./build/browser/public/*.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"zod": "^4.1.7"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"rimraf": "^6.0.1",
|
|
35
|
+
"tslib": "^2.8.1",
|
|
36
|
+
"typescript": "^5.9.2",
|
|
37
|
+
"@palantir/pack.monorepo.tsconfig": "~0.4.0-beta.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"main": "./build/cjs/index.js",
|
|
43
|
+
"module": "./build/esm/index.js",
|
|
44
|
+
"types": "./build/cjs/index.d.ts",
|
|
45
|
+
"type": "module",
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rimraf .turbo build dist lib test-output *.tgz tsconfig.tsbuildinfo",
|
|
48
|
+
"lint": "eslint ./src ; dprint check --config $(find-up dprint.json) --allow-no-files",
|
|
49
|
+
"lint:fix": "eslint ./src --fix ; dprint fmt --config $(find-up dprint.json) --allow-no-files",
|
|
50
|
+
"test": "vitest run --passWithNoTests -u",
|
|
51
|
+
"test:watch": "vitest --passWithNoTests",
|
|
52
|
+
"transpileBrowser": "monorepo-transpile -f esm -m bundle -t browser",
|
|
53
|
+
"transpileCjs": "monorepo-transpile -f cjs -m bundle -t node",
|
|
54
|
+
"transpileEsm": "monorepo-transpile -f esm -m bundle -t node",
|
|
55
|
+
"transpileTypes": "monorepo-transpile -f esm -m types -t node",
|
|
56
|
+
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
export type {
|
|
18
|
+
DocumentSchema,
|
|
19
|
+
DocumentSchemaMetadata,
|
|
20
|
+
DocumentState,
|
|
21
|
+
} from "./types/DocumentSchema.js";
|
|
22
|
+
export { getMetadata, Metadata } from "./types/Metadata.js";
|
|
23
|
+
export type { WithMetadata } from "./types/Metadata.js";
|
|
24
|
+
export type { Model, ModelData, ModelMetadata } from "./types/Model.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
import type { WithMetadata } from "./Metadata.js";
|
|
18
|
+
import type { Model, ModelData } from "./Model.js";
|
|
19
|
+
|
|
20
|
+
export interface DocumentSchema extends WithMetadata<DocumentSchemaMetadata> {
|
|
21
|
+
readonly [modelName: string]: Model;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type DocumentState<S extends DocumentSchema> = {
|
|
25
|
+
readonly [K in Exclude<keyof S, symbol>]: { readonly [key: string]: ModelData<S[K]> };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface DocumentSchemaMetadata {
|
|
29
|
+
readonly version: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
export const Metadata: symbol = Symbol("@pack/document-schema/metadata");
|
|
18
|
+
|
|
19
|
+
export interface WithMetadata<T> {
|
|
20
|
+
readonly [Metadata]: T;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMetadata<T>(obj: WithMetadata<T>): T {
|
|
24
|
+
// TS always treats symbol keys as optional
|
|
25
|
+
const metadata = obj[Metadata];
|
|
26
|
+
if (metadata == null) {
|
|
27
|
+
throw new Error("Object does not have metadata");
|
|
28
|
+
}
|
|
29
|
+
return metadata;
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
import type { ZodType } from "zod";
|
|
18
|
+
import type { WithMetadata } from "./Metadata.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A Model defines the structure of a document record or union.
|
|
22
|
+
*
|
|
23
|
+
* It includes a zod schema for validation and type information.
|
|
24
|
+
*/
|
|
25
|
+
// TODO: I think we can/should hide the zod types
|
|
26
|
+
export interface Model<T = unknown, Z extends ZodType<T> = ZodType<T>>
|
|
27
|
+
extends WithMetadata<ModelMetadata>
|
|
28
|
+
{
|
|
29
|
+
readonly __type: T;
|
|
30
|
+
readonly zodSchema: Readonly<Z>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ModelData<M extends Model> = M["__type"];
|
|
34
|
+
|
|
35
|
+
export interface ModelMetadata {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@palantir/pack.monorepo.tsconfig/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./build/esm",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"declarationDir": "./build/types",
|
|
7
|
+
"tsBuildInfoFile": "./build/tsconfig.tsbuildinfo"
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src/**/*"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"build",
|
|
14
|
+
"dist",
|
|
15
|
+
"node_modules",
|
|
16
|
+
"test-output",
|
|
17
|
+
"**/__tests__/**/__snapshots__",
|
|
18
|
+
"**/__tests__/**/fixtures"
|
|
19
|
+
],
|
|
20
|
+
"references": []
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { coverageConfigDefaults, defaultExclude, defineProject } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
export default defineProject({
|
|
4
|
+
test: {
|
|
5
|
+
exclude: [...defaultExclude, "**/build/**", "**/test-output/**"],
|
|
6
|
+
coverage: {
|
|
7
|
+
provider: "v8",
|
|
8
|
+
all: true,
|
|
9
|
+
enabled: true,
|
|
10
|
+
pool: "forks",
|
|
11
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
12
|
+
exclude: [
|
|
13
|
+
...coverageConfigDefaults.exclude,
|
|
14
|
+
"**/*.test.{ts,tsx}",
|
|
15
|
+
"**/__tests__",
|
|
16
|
+
"build",
|
|
17
|
+
"coverage",
|
|
18
|
+
"dist",
|
|
19
|
+
"node_modules",
|
|
20
|
+
"src/index.ts",
|
|
21
|
+
"test-output",
|
|
22
|
+
"vitest.config.*",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|