@palantir/pack.core 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 +4 -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 +7 -0
- package/build/browser/index.js +50 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +56 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +207 -0
- package/build/esm/index.js +50 -0
- package/build/esm/index.js.map +1 -0
- package/build/types/index.d.ts +10 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/types/AppConfig.d.ts +68 -0
- package/build/types/types/AppConfig.d.ts.map +1 -0
- package/build/types/types/Branded.d.ts +29 -0
- package/build/types/types/Branded.d.ts.map +1 -0
- package/build/types/types/ModuleKey.d.ts +53 -0
- package/build/types/types/ModuleKey.d.ts.map +1 -0
- package/build/types/types/PackApp.d.ts +49 -0
- package/build/types/types/PackApp.d.ts.map +1 -0
- package/build/types/types/TokenProvider.d.ts +1 -0
- package/build/types/types/TokenProvider.d.ts.map +1 -0
- package/build/types/types/Unsubscribe.d.ts +1 -0
- package/build/types/types/Unsubscribe.d.ts.map +1 -0
- package/build/types/utils/assertNever.d.ts +1 -0
- package/build/types/utils/assertNever.d.ts.map +1 -0
- package/build/types/utils/generateId.d.ts +1 -0
- package/build/types/utils/generateId.d.ts.map +1 -0
- package/build/types/utils/justOnce.d.ts +10 -0
- package/build/types/utils/justOnce.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/index.ts +26 -0
- package/src/types/AppConfig.ts +97 -0
- package/src/types/Branded.ts +44 -0
- package/src/types/ModuleKey.ts +67 -0
- package/src/types/PackApp.ts +82 -0
- package/src/types/TokenProvider.ts +17 -0
- package/src/types/Unsubscribe.ts +17 -0
- package/src/utils/assertNever.ts +19 -0
- package/src/utils/generateId.ts +28 -0
- package/src/utils/justOnce.ts +33 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mjs +26 -0
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,7 @@
|
|
|
1
|
+
# @palantir/pack.core
|
|
2
|
+
|
|
3
|
+
Core functionality and utilities used across all PACK packages, providing shared types and utilities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package contains the fundamental building blocks for PACK applications, including type definitions, utility functions, and core interfaces that other PACK packages depend on.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
2
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
3
|
+
var prefix = "Invariant failed";
|
|
4
|
+
function invariant(condition, message) {
|
|
5
|
+
if (isProduction) {
|
|
6
|
+
throw new Error(prefix);
|
|
7
|
+
}
|
|
8
|
+
var provided = typeof message === "function" ? message() : message;
|
|
9
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
10
|
+
throw new Error(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/types/PackApp.ts
|
|
14
|
+
var isModuleConfigTuple = (config) => {
|
|
15
|
+
return Array.isArray(config);
|
|
16
|
+
};
|
|
17
|
+
function assertIsAppInternal(app) {
|
|
18
|
+
!("getModule" in app) ? process.env.NODE_ENV !== "production" ? invariant(false, "App is not an PackAppInternal") : invariant() : void 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/utils/assertNever.ts
|
|
22
|
+
function assertNever(_x) {
|
|
23
|
+
throw new Error("Hit unreachable code");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/utils/generateId.ts
|
|
27
|
+
function toHexString(byteArray) {
|
|
28
|
+
return Array.from(byteArray, function(byte) {
|
|
29
|
+
const h = (byte & 255).toString(16);
|
|
30
|
+
return h.length === 1 ? `0${h}` : h;
|
|
31
|
+
}).join("");
|
|
32
|
+
}
|
|
33
|
+
function generateId(bytes = 12) {
|
|
34
|
+
const array = new Int8Array(bytes);
|
|
35
|
+
const r = crypto.getRandomValues(array);
|
|
36
|
+
return toHexString(r);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/utils/justOnce.ts
|
|
40
|
+
var SEEN_KEYS = /* @__PURE__ */ new Set();
|
|
41
|
+
function justOnce(key, fn) {
|
|
42
|
+
if (!SEEN_KEYS.has(key)) {
|
|
43
|
+
SEEN_KEYS.add(key);
|
|
44
|
+
fn();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { assertIsAppInternal, assertNever, generateId, isModuleConfigTuple, justOnce };
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js","../../src/types/PackApp.ts","../../src/utils/assertNever.ts","../../src/utils/generateId.ts","../../src/utils/justOnce.ts"],"names":[],"mappings":";AAAA,IAAI,YAAA,GAAe,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA;AAC5C,IAAI,MAAA,GAAS,kBAAA;AACb,SAAS,SAAA,CAAU,WAAW,OAAA,EAAS;AAIrC,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,MAAM,IAAI,MAAM,MAAM,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,QAAA,GAAW,OAAO,OAAA,KAAY,UAAA,GAAa,SAAQ,GAAI,OAAA;AAC3D,EAAA,IAAI,KAAA,GAAQ,WAAW,EAAA,CAAG,MAAA,CAAO,QAAQ,IAAI,CAAA,CAAE,MAAA,CAAO,QAAQ,CAAA,GAAI,MAAA;AAClE,EAAA,MAAM,IAAI,MAAM,KAAK,CAAA;AACvB;;;ACqCO,IAAM,sBAAsB,CAAA,MAAA,KAAU;AAC3C,EAAA,OAAO,KAAA,CAAM,QAAQ,MAAM,CAAA;AAC7B;AACO,SAAS,oBAAoB,GAAA,EAAK;AACvC,EAAA,EAAE,WAAA,IAAe,GAAA,CAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,GAAe,SAAA,CAAU,KAAA,EAAO,+BAA+B,CAAA,GAAI,SAAA,CAAe,CAAA,GAAI,MAAA;AACzI;;;ACtCO,SAAS,YAAY,EAAA,EAAI;AAC9B,EAAA,MAAM,IAAI,MAAM,sBAAsB,CAAA;AACxC;;;ACFA,SAAS,YAAY,SAAA,EAAW;AAC9B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,SAAU,IAAA,EAAM;AAC3C,IAAA,MAAM,CAAA,GAAA,CAAK,IAAA,GAAO,GAAA,EAAM,QAAA,CAAS,EAAE,CAAA;AACnC,IAAA,OAAO,CAAA,CAAE,MAAA,KAAW,CAAA,GAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,GAAK,CAAA;AAAA,EACpC,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA;AACZ;AACO,SAAS,UAAA,CAAW,QAAQ,EAAA,EAAI;AACrC,EAAA,MAAM,KAAA,GAAQ,IAAI,SAAA,CAAU,KAAK,CAAA;AACjC,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,eAAA,CAAgB,KAAK,CAAA;AACtC,EAAA,OAAO,YAAY,CAAC,CAAA;AACtB;;;ACVA,IAAM,SAAA,uBAAgB,GAAA,EAAI;AAWnB,SAAS,QAAA,CAAS,KAAK,EAAA,EAAI;AAChC,EAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AACvB,IAAA,SAAA,CAAU,IAAI,GAAG,CAAA;AACjB,IAAA,EAAA,EAAG;AAAA,EACL;AACF","file":"index.js","sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\nexport { invariant as default };","/*\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\nimport invariant from \"tiny-invariant\";\n\n/**\n * PackApp provides access to various pack subsystems.\n *\n * Specific modules are available after configuration and through declarations mixed in by import.\n * Eg for state system, if you import @palantir/pack.state.core you will have access to `app.state` accessor.\n * Similarly, auth is added automatically by initPackApp.\n *\n * @example\n * ```typescript\n * import { DocumentRef } from '@palantir/pack.state.core';\n * import { DocSchema } from '@my-app/schema';\n *\n * const app = initPackApp({\n * tokenProvider: () => 'your-token',\n * moduleConfigs: {\n * ...createPackDocumentServiceConfig({appId: 'your-app-id', documentType: 'your-document-type'})\n * },\n * });\n *\n * const docRef = app.state.getDocument(docSchema, 'your-document-id');\n * const doc = await docRef.getSnapshot(); // get pojo of your doc state.\n * ```\n */\n\n/**\n * Module configuration - either a tuple of [ModuleKey, config] or just a ModuleKey (for modules with no config)\n */\n\n/**\n * Type guard to check if a ModuleConfig is a tuple configuration\n */\nexport const isModuleConfigTuple = config => {\n return Array.isArray(config);\n};\nexport function assertIsAppInternal(app) {\n !(\"getModule\" in app) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"App is not an PackAppInternal\") : invariant(false) : void 0;\n}","/*\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 function assertNever(_x) {\n throw new Error(\"Hit unreachable code\");\n}","/*\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\nfunction toHexString(byteArray) {\n return Array.from(byteArray, function (byte) {\n const h = (byte & 0xff).toString(16);\n return h.length === 1 ? `0${h}` : h;\n }).join(\"\");\n}\nexport function generateId(bytes = 12) {\n const array = new Int8Array(bytes);\n const r = crypto.getRandomValues(array);\n return toHexString(r);\n}","/*\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\nconst SEEN_KEYS = new Set();\n\n/**\n * Used to call fn only once between app reloads.\n * eg: Useful for logging warnings that should only be logged once.\n *\n * @example\n * ```ts\n * justOnce(\"unexpected-value\", () => console.warn(\"There was an unexpected value returned\", {value}));\n * ```\n */\nexport function justOnce(key, fn) {\n if (!SEEN_KEYS.has(key)) {\n SEEN_KEYS.add(key);\n fn();\n }\n}"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
4
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
5
|
+
var prefix = "Invariant failed";
|
|
6
|
+
function invariant(condition, message) {
|
|
7
|
+
if (isProduction) {
|
|
8
|
+
throw new Error(prefix);
|
|
9
|
+
}
|
|
10
|
+
var provided = typeof message === "function" ? message() : message;
|
|
11
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
12
|
+
throw new Error(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/types/PackApp.ts
|
|
16
|
+
var isModuleConfigTuple = (config) => {
|
|
17
|
+
return Array.isArray(config);
|
|
18
|
+
};
|
|
19
|
+
function assertIsAppInternal(app) {
|
|
20
|
+
!("getModule" in app) ? process.env.NODE_ENV !== "production" ? invariant(false, "App is not an PackAppInternal") : invariant() : void 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/utils/assertNever.ts
|
|
24
|
+
function assertNever(_x) {
|
|
25
|
+
throw new Error("Hit unreachable code");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/utils/generateId.ts
|
|
29
|
+
function toHexString(byteArray) {
|
|
30
|
+
return Array.from(byteArray, function(byte) {
|
|
31
|
+
const h = (byte & 255).toString(16);
|
|
32
|
+
return h.length === 1 ? `0${h}` : h;
|
|
33
|
+
}).join("");
|
|
34
|
+
}
|
|
35
|
+
function generateId(bytes = 12) {
|
|
36
|
+
const array = new Int8Array(bytes);
|
|
37
|
+
const r = crypto.getRandomValues(array);
|
|
38
|
+
return toHexString(r);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/utils/justOnce.ts
|
|
42
|
+
var SEEN_KEYS = /* @__PURE__ */ new Set();
|
|
43
|
+
function justOnce(key, fn) {
|
|
44
|
+
if (!SEEN_KEYS.has(key)) {
|
|
45
|
+
SEEN_KEYS.add(key);
|
|
46
|
+
fn();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.assertIsAppInternal = assertIsAppInternal;
|
|
51
|
+
exports.assertNever = assertNever;
|
|
52
|
+
exports.generateId = generateId;
|
|
53
|
+
exports.isModuleConfigTuple = isModuleConfigTuple;
|
|
54
|
+
exports.justOnce = justOnce;
|
|
55
|
+
//# sourceMappingURL=index.cjs.map
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js","../../src/types/PackApp.ts","../../src/utils/assertNever.ts","../../src/utils/generateId.ts","../../src/utils/justOnce.ts"],"names":[],"mappings":";;;AAAA,IAAI,YAAA,GAAe,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA;AAC5C,IAAI,MAAA,GAAS,kBAAA;AACb,SAAS,SAAA,CAAU,WAAW,OAAA,EAAS;AAIrC,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,MAAM,IAAI,MAAM,MAAM,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,QAAA,GAAW,OAAO,OAAA,KAAY,UAAA,GAAa,SAAQ,GAAI,OAAA;AAC3D,EAAA,IAAI,KAAA,GAAQ,WAAW,EAAA,CAAG,MAAA,CAAO,QAAQ,IAAI,CAAA,CAAE,MAAA,CAAO,QAAQ,CAAA,GAAI,MAAA;AAClE,EAAA,MAAM,IAAI,MAAM,KAAK,CAAA;AACvB;;;ACqCO,IAAM,sBAAsB,CAAA,MAAA,KAAU;AAC3C,EAAA,OAAO,KAAA,CAAM,QAAQ,MAAM,CAAA;AAC7B;AACO,SAAS,oBAAoB,GAAA,EAAK;AACvC,EAAA,EAAE,WAAA,IAAe,GAAA,CAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,GAAe,SAAA,CAAU,KAAA,EAAO,+BAA+B,CAAA,GAAI,SAAA,CAAe,CAAA,GAAI,MAAA;AACzI;;;ACtCO,SAAS,YAAY,EAAA,EAAI;AAC9B,EAAA,MAAM,IAAI,MAAM,sBAAsB,CAAA;AACxC;;;ACFA,SAAS,YAAY,SAAA,EAAW;AAC9B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,SAAU,IAAA,EAAM;AAC3C,IAAA,MAAM,CAAA,GAAA,CAAK,IAAA,GAAO,GAAA,EAAM,QAAA,CAAS,EAAE,CAAA;AACnC,IAAA,OAAO,CAAA,CAAE,MAAA,KAAW,CAAA,GAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,GAAK,CAAA;AAAA,EACpC,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA;AACZ;AACO,SAAS,UAAA,CAAW,QAAQ,EAAA,EAAI;AACrC,EAAA,MAAM,KAAA,GAAQ,IAAI,SAAA,CAAU,KAAK,CAAA;AACjC,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,eAAA,CAAgB,KAAK,CAAA;AACtC,EAAA,OAAO,YAAY,CAAC,CAAA;AACtB;;;ACVA,IAAM,SAAA,uBAAgB,GAAA,EAAI;AAWnB,SAAS,QAAA,CAAS,KAAK,EAAA,EAAI;AAChC,EAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AACvB,IAAA,SAAA,CAAU,IAAI,GAAG,CAAA;AACjB,IAAA,EAAA,EAAG;AAAA,EACL;AACF","file":"index.cjs","sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\nexport { invariant as default };","/*\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\nimport invariant from \"tiny-invariant\";\n\n/**\n * PackApp provides access to various pack subsystems.\n *\n * Specific modules are available after configuration and through declarations mixed in by import.\n * Eg for state system, if you import @palantir/pack.state.core you will have access to `app.state` accessor.\n * Similarly, auth is added automatically by initPackApp.\n *\n * @example\n * ```typescript\n * import { DocumentRef } from '@palantir/pack.state.core';\n * import { DocSchema } from '@my-app/schema';\n *\n * const app = initPackApp({\n * tokenProvider: () => 'your-token',\n * moduleConfigs: {\n * ...createPackDocumentServiceConfig({appId: 'your-app-id', documentType: 'your-document-type'})\n * },\n * });\n *\n * const docRef = app.state.getDocument(docSchema, 'your-document-id');\n * const doc = await docRef.getSnapshot(); // get pojo of your doc state.\n * ```\n */\n\n/**\n * Module configuration - either a tuple of [ModuleKey, config] or just a ModuleKey (for modules with no config)\n */\n\n/**\n * Type guard to check if a ModuleConfig is a tuple configuration\n */\nexport const isModuleConfigTuple = config => {\n return Array.isArray(config);\n};\nexport function assertIsAppInternal(app) {\n !(\"getModule\" in app) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"App is not an PackAppInternal\") : invariant(false) : void 0;\n}","/*\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 function assertNever(_x) {\n throw new Error(\"Hit unreachable code\");\n}","/*\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\nfunction toHexString(byteArray) {\n return Array.from(byteArray, function (byte) {\n const h = (byte & 0xff).toString(16);\n return h.length === 1 ? `0${h}` : h;\n }).join(\"\");\n}\nexport function generateId(bytes = 12) {\n const array = new Int8Array(bytes);\n const r = crypto.getRandomValues(array);\n return toHexString(r);\n}","/*\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\nconst SEEN_KEYS = new Set();\n\n/**\n * Used to call fn only once between app reloads.\n * eg: Useful for logging warnings that should only be logged once.\n *\n * @example\n * ```ts\n * justOnce(\"unexpected-value\", () => console.warn(\"There was an unexpected value returned\", {value}));\n * ```\n */\nexport function justOnce(key, fn) {\n if (!SEEN_KEYS.has(key)) {\n SEEN_KEYS.add(key);\n fn();\n }\n}"]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Logger } from '@osdk/api';
|
|
2
|
+
import { Client } from '@osdk/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ModuleKey uniquely identifies a module.
|
|
6
|
+
*
|
|
7
|
+
* The key is a symbol and is used to identify the module config.
|
|
8
|
+
* Modules are lazily initialized on first access.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const MY_MODULE_ACCESSOR = "myModule";
|
|
13
|
+
*
|
|
14
|
+
* const MY_MODULE_KEY: ModuleKey<MyModule, MyModuleConfig> = {
|
|
15
|
+
* key: Symbol.for("my.module"),
|
|
16
|
+
*
|
|
17
|
+
* appMemberName: MY_MODULE_ACCESSOR,
|
|
18
|
+
* initModule: initMyModule,
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* const app = initPackApp({
|
|
22
|
+
* moduleConfig: {
|
|
23
|
+
* [MY_MODULE_KEY.key]: { ... config ... } satisfies MyModuleConfig
|
|
24
|
+
*
|
|
25
|
+
* // Note this is the actual shape of the moduleConfig, ie index by module key symbol
|
|
26
|
+
* // But it is far more ergonomic to spread from a config creator, ie:
|
|
27
|
+
* ...createMyModuleConfig({ ... config ... }),
|
|
28
|
+
* }
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* // Get the module (manual way)
|
|
32
|
+
* const myModule = app.getModule(MY_MODULE_KEY);
|
|
33
|
+
*
|
|
34
|
+
* // Get the module from app property (available via appMemberName sugar)
|
|
35
|
+
* // You also need to declare the appMemberName on the PackApp interface so the type
|
|
36
|
+
* // system knows it is present. This keeps your module usage limited to where your module
|
|
37
|
+
* // is imported
|
|
38
|
+
* declare module '@palantir/pack.core' {
|
|
39
|
+
* interface PackApp {
|
|
40
|
+
* readonly [MY_MODULE_ACCESSOR]?: MyModule;
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* const myModule = app.myModule;
|
|
44
|
+
*
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
interface ModuleKey<T, TConfig = unknown> {
|
|
48
|
+
/** If set, this module will have a getter installed on the PackApp interface */
|
|
49
|
+
readonly appMemberName?: string;
|
|
50
|
+
readonly key: symbol;
|
|
51
|
+
readonly initModule: (app: PackAppInternal, config?: TConfig) => T;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* PackApp provides access to various pack subsystems.
|
|
56
|
+
*
|
|
57
|
+
* Specific modules are available after configuration and through declarations mixed in by import.
|
|
58
|
+
* Eg for state system, if you import @palantir/pack.state.core you will have access to `app.state` accessor.
|
|
59
|
+
* Similarly, auth is added automatically by initPackApp.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { DocumentRef } from '@palantir/pack.state.core';
|
|
64
|
+
* import { DocSchema } from '@my-app/schema';
|
|
65
|
+
*
|
|
66
|
+
* const app = initPackApp({
|
|
67
|
+
* tokenProvider: () => 'your-token',
|
|
68
|
+
* moduleConfigs: {
|
|
69
|
+
* ...createPackDocumentServiceConfig({appId: 'your-app-id', documentType: 'your-document-type'})
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const docRef = app.state.getDocument(docSchema, 'your-document-id');
|
|
74
|
+
* const doc = await docRef.getSnapshot(); // get pojo of your doc state.
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
interface PackApp {
|
|
78
|
+
readonly config: AppConfig;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Module configuration - either a tuple of [ModuleKey, config] or just a ModuleKey (for modules with no config)
|
|
82
|
+
*/
|
|
83
|
+
type ModuleConfigTuple<T = unknown> = readonly [ModuleKey<T>, unknown];
|
|
84
|
+
type ModuleConfig<T = unknown> = ModuleConfigTuple<T> | ModuleKey<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Type guard to check if a ModuleConfig is a tuple configuration
|
|
87
|
+
*/
|
|
88
|
+
declare const isModuleConfigTuple: (config: ModuleConfig) => config is readonly [ModuleKey<unknown>, unknown];
|
|
89
|
+
interface PackAppInternal {
|
|
90
|
+
readonly config: AppConfig;
|
|
91
|
+
/**
|
|
92
|
+
* Internal module accessor
|
|
93
|
+
*/
|
|
94
|
+
getModule<T, TConfig = undefined>(moduleKey: ModuleKey<T, TConfig>): T;
|
|
95
|
+
}
|
|
96
|
+
declare function assertIsAppInternal(app: PackApp): asserts app is PackApp & PackAppInternal;
|
|
97
|
+
declare function assertIsAppInternal(app: PackAppInternal): asserts app is PackAppInternal;
|
|
98
|
+
|
|
99
|
+
type TokenProvider = () => Promise<string>;
|
|
100
|
+
|
|
101
|
+
interface AppConfig {
|
|
102
|
+
readonly app: {
|
|
103
|
+
readonly appId: string;
|
|
104
|
+
readonly appVersion?: string;
|
|
105
|
+
};
|
|
106
|
+
readonly isTestMode: boolean;
|
|
107
|
+
readonly logger: Logger;
|
|
108
|
+
readonly osdkClient: Client;
|
|
109
|
+
readonly remote: {
|
|
110
|
+
readonly packApiPath: string;
|
|
111
|
+
readonly packWsPath: string;
|
|
112
|
+
readonly baseUrl: string;
|
|
113
|
+
readonly fetchFn: typeof globalThis.fetch;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
interface AppOptions {
|
|
117
|
+
/**
|
|
118
|
+
* Override the authentication token provider from the OSDK client.
|
|
119
|
+
*
|
|
120
|
+
* @default Uses token provider from OSDK client
|
|
121
|
+
*/
|
|
122
|
+
readonly auth?: TokenProvider;
|
|
123
|
+
/**
|
|
124
|
+
* The ID of your application.
|
|
125
|
+
* @default Uses values from page environment meta tags (pack-appId, pack-appVersion)
|
|
126
|
+
*/
|
|
127
|
+
readonly app?: {
|
|
128
|
+
readonly appId: string;
|
|
129
|
+
readonly appVersion?: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Logger configuration.
|
|
133
|
+
* @see {@link @osdk/client/internal.BrowserLogger} for a richer console logger.
|
|
134
|
+
* @default Log warnings & errors only.
|
|
135
|
+
*/
|
|
136
|
+
readonly logger?: Logger;
|
|
137
|
+
readonly logLevel?: "debug" | "error" | "info" | "warn";
|
|
138
|
+
/**
|
|
139
|
+
* Internal testing overrides.
|
|
140
|
+
*/
|
|
141
|
+
readonly moduleOverrides?: readonly ModuleConfigTuple[];
|
|
142
|
+
readonly remote?: {
|
|
143
|
+
/**
|
|
144
|
+
* @default "/pack/api"
|
|
145
|
+
*/
|
|
146
|
+
readonly packApiPath?: string;
|
|
147
|
+
/**
|
|
148
|
+
* @default "/pack/ws"
|
|
149
|
+
*/
|
|
150
|
+
readonly packWsPath?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Override the base URL from the OSDK client.
|
|
153
|
+
*
|
|
154
|
+
* eg "https://example.com"
|
|
155
|
+
*
|
|
156
|
+
* @default Uses base URL from OSDK client
|
|
157
|
+
*/
|
|
158
|
+
readonly baseUrl?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Override the fetch function from the OSDK client.
|
|
161
|
+
*/
|
|
162
|
+
readonly fetchFn?: typeof globalThis.fetch;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
type Branded<Brand extends string, T = string> = T & Readonly<{
|
|
167
|
+
readonly __pack_brand: Brand;
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* A type that is "flavored" for self documenting code and prevents some accidental misuse.
|
|
171
|
+
* This is similar to {@link Branded} but allows implicit use of T without a type assertion,
|
|
172
|
+
* which is useful for stronger typing within certain systems without forcing it for all
|
|
173
|
+
* external uses.
|
|
174
|
+
*
|
|
175
|
+
* Flavored types with different brands will not match.
|
|
176
|
+
* A Branded type with the same brand will implicitly match a Flavored type with the same brand,
|
|
177
|
+
* ie `const foo: Flavored<"foo"> = "foo" as Branded<"foo">`
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* type MyId = Flavored<"MyId">;
|
|
181
|
+
* type OtherId = Flavored<"OtherId">;
|
|
182
|
+
* const id: MyId = "my-id"; // Good: No type assertion needed
|
|
183
|
+
* const otherId: OtherId = id; // Error: Type 'MyId' is not assignable to type 'OtherId'
|
|
184
|
+
* const otherId: OtherId = id as OtherId; // You can assert between flavored types directly
|
|
185
|
+
*/
|
|
186
|
+
type Flavored<Flavor extends string, T = string> = T & Readonly<{
|
|
187
|
+
readonly __pack_brand?: Flavor;
|
|
188
|
+
}>;
|
|
189
|
+
|
|
190
|
+
type Unsubscribe = () => void;
|
|
191
|
+
|
|
192
|
+
declare function assertNever(_x: never): never;
|
|
193
|
+
|
|
194
|
+
declare function generateId(bytes?: number): string;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Used to call fn only once between app reloads.
|
|
198
|
+
* eg: Useful for logging warnings that should only be logged once.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* justOnce("unexpected-value", () => console.warn("There was an unexpected value returned", {value}));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
declare function justOnce(key: string, fn: () => void): void;
|
|
206
|
+
|
|
207
|
+
export { type AppConfig, type AppOptions, type Branded, type Flavored, type ModuleConfig, type ModuleConfigTuple, type ModuleKey, type PackApp, type PackAppInternal, type TokenProvider, type Unsubscribe, assertIsAppInternal, assertNever, generateId, isModuleConfigTuple, justOnce };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js
|
|
2
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
3
|
+
var prefix = "Invariant failed";
|
|
4
|
+
function invariant(condition, message) {
|
|
5
|
+
if (isProduction) {
|
|
6
|
+
throw new Error(prefix);
|
|
7
|
+
}
|
|
8
|
+
var provided = typeof message === "function" ? message() : message;
|
|
9
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
10
|
+
throw new Error(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/types/PackApp.ts
|
|
14
|
+
var isModuleConfigTuple = (config) => {
|
|
15
|
+
return Array.isArray(config);
|
|
16
|
+
};
|
|
17
|
+
function assertIsAppInternal(app) {
|
|
18
|
+
!("getModule" in app) ? process.env.NODE_ENV !== "production" ? invariant(false, "App is not an PackAppInternal") : invariant() : void 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/utils/assertNever.ts
|
|
22
|
+
function assertNever(_x) {
|
|
23
|
+
throw new Error("Hit unreachable code");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/utils/generateId.ts
|
|
27
|
+
function toHexString(byteArray) {
|
|
28
|
+
return Array.from(byteArray, function(byte) {
|
|
29
|
+
const h = (byte & 255).toString(16);
|
|
30
|
+
return h.length === 1 ? `0${h}` : h;
|
|
31
|
+
}).join("");
|
|
32
|
+
}
|
|
33
|
+
function generateId(bytes = 12) {
|
|
34
|
+
const array = new Int8Array(bytes);
|
|
35
|
+
const r = crypto.getRandomValues(array);
|
|
36
|
+
return toHexString(r);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/utils/justOnce.ts
|
|
40
|
+
var SEEN_KEYS = /* @__PURE__ */ new Set();
|
|
41
|
+
function justOnce(key, fn) {
|
|
42
|
+
if (!SEEN_KEYS.has(key)) {
|
|
43
|
+
SEEN_KEYS.add(key);
|
|
44
|
+
fn();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { assertIsAppInternal, assertNever, generateId, isModuleConfigTuple, justOnce };
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js","../../src/types/PackApp.ts","../../src/utils/assertNever.ts","../../src/utils/generateId.ts","../../src/utils/justOnce.ts"],"names":[],"mappings":";AAAA,IAAI,YAAA,GAAe,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA;AAC5C,IAAI,MAAA,GAAS,kBAAA;AACb,SAAS,SAAA,CAAU,WAAW,OAAA,EAAS;AAIrC,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,MAAM,IAAI,MAAM,MAAM,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,QAAA,GAAW,OAAO,OAAA,KAAY,UAAA,GAAa,SAAQ,GAAI,OAAA;AAC3D,EAAA,IAAI,KAAA,GAAQ,WAAW,EAAA,CAAG,MAAA,CAAO,QAAQ,IAAI,CAAA,CAAE,MAAA,CAAO,QAAQ,CAAA,GAAI,MAAA;AAClE,EAAA,MAAM,IAAI,MAAM,KAAK,CAAA;AACvB;;;ACqCO,IAAM,sBAAsB,CAAA,MAAA,KAAU;AAC3C,EAAA,OAAO,KAAA,CAAM,QAAQ,MAAM,CAAA;AAC7B;AACO,SAAS,oBAAoB,GAAA,EAAK;AACvC,EAAA,EAAE,WAAA,IAAe,GAAA,CAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,GAAe,SAAA,CAAU,KAAA,EAAO,+BAA+B,CAAA,GAAI,SAAA,CAAe,CAAA,GAAI,MAAA;AACzI;;;ACtCO,SAAS,YAAY,EAAA,EAAI;AAC9B,EAAA,MAAM,IAAI,MAAM,sBAAsB,CAAA;AACxC;;;ACFA,SAAS,YAAY,SAAA,EAAW;AAC9B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,SAAU,IAAA,EAAM;AAC3C,IAAA,MAAM,CAAA,GAAA,CAAK,IAAA,GAAO,GAAA,EAAM,QAAA,CAAS,EAAE,CAAA;AACnC,IAAA,OAAO,CAAA,CAAE,MAAA,KAAW,CAAA,GAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,GAAK,CAAA;AAAA,EACpC,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA;AACZ;AACO,SAAS,UAAA,CAAW,QAAQ,EAAA,EAAI;AACrC,EAAA,MAAM,KAAA,GAAQ,IAAI,SAAA,CAAU,KAAK,CAAA;AACjC,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,eAAA,CAAgB,KAAK,CAAA;AACtC,EAAA,OAAO,YAAY,CAAC,CAAA;AACtB;;;ACVA,IAAM,SAAA,uBAAgB,GAAA,EAAI;AAWnB,SAAS,QAAA,CAAS,KAAK,EAAA,EAAI;AAChC,EAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA,EAAG;AACvB,IAAA,SAAA,CAAU,IAAI,GAAG,CAAA;AACjB,IAAA,EAAA,EAAG;AAAA,EACL;AACF","file":"index.js","sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\nexport { invariant as default };","/*\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\nimport invariant from \"tiny-invariant\";\n\n/**\n * PackApp provides access to various pack subsystems.\n *\n * Specific modules are available after configuration and through declarations mixed in by import.\n * Eg for state system, if you import @palantir/pack.state.core you will have access to `app.state` accessor.\n * Similarly, auth is added automatically by initPackApp.\n *\n * @example\n * ```typescript\n * import { DocumentRef } from '@palantir/pack.state.core';\n * import { DocSchema } from '@my-app/schema';\n *\n * const app = initPackApp({\n * tokenProvider: () => 'your-token',\n * moduleConfigs: {\n * ...createPackDocumentServiceConfig({appId: 'your-app-id', documentType: 'your-document-type'})\n * },\n * });\n *\n * const docRef = app.state.getDocument(docSchema, 'your-document-id');\n * const doc = await docRef.getSnapshot(); // get pojo of your doc state.\n * ```\n */\n\n/**\n * Module configuration - either a tuple of [ModuleKey, config] or just a ModuleKey (for modules with no config)\n */\n\n/**\n * Type guard to check if a ModuleConfig is a tuple configuration\n */\nexport const isModuleConfigTuple = config => {\n return Array.isArray(config);\n};\nexport function assertIsAppInternal(app) {\n !(\"getModule\" in app) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"App is not an PackAppInternal\") : invariant(false) : void 0;\n}","/*\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 function assertNever(_x) {\n throw new Error(\"Hit unreachable code\");\n}","/*\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\nfunction toHexString(byteArray) {\n return Array.from(byteArray, function (byte) {\n const h = (byte & 0xff).toString(16);\n return h.length === 1 ? `0${h}` : h;\n }).join(\"\");\n}\nexport function generateId(bytes = 12) {\n const array = new Int8Array(bytes);\n const r = crypto.getRandomValues(array);\n return toHexString(r);\n}","/*\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\nconst SEEN_KEYS = new Set();\n\n/**\n * Used to call fn only once between app reloads.\n * eg: Useful for logging warnings that should only be logged once.\n *\n * @example\n * ```ts\n * justOnce(\"unexpected-value\", () => console.warn(\"There was an unexpected value returned\", {value}));\n * ```\n */\nexport function justOnce(key, fn) {\n if (!SEEN_KEYS.has(key)) {\n SEEN_KEYS.add(key);\n fn();\n }\n}"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { AppConfig, AppOptions } from "./types/AppConfig.js";
|
|
2
|
+
export type { Branded, Flavored } from "./types/Branded.js";
|
|
3
|
+
export type { ModuleKey } from "./types/ModuleKey.js";
|
|
4
|
+
export { assertIsAppInternal, isModuleConfigTuple } from "./types/PackApp.js";
|
|
5
|
+
export type { ModuleConfig, ModuleConfigTuple, PackApp, PackAppInternal } from "./types/PackApp.js";
|
|
6
|
+
export type { TokenProvider } from "./types/TokenProvider.js";
|
|
7
|
+
export type { Unsubscribe } from "./types/Unsubscribe.js";
|
|
8
|
+
export { assertNever } from "./utils/assertNever.js";
|
|
9
|
+
export { generateId } from "./utils/generateId.js";
|
|
10
|
+
export { justOnce } from "./utils/justOnce.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,WAAW,kBAAkB;AAC3C,cAAc,SAAS,gBAAgB;AACvC,cAAc,iBAAiB;AAC/B,SAAS,qBAAqB,2BAA2B;AACzD,cAAc,cAAc,mBAAmB,SAAS,uBAAuB;AAC/E,cAAc,qBAAqB;AACnC,cAAc,mBAAmB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Logger } from "@osdk/api";
|
|
2
|
+
import type { Client } from "@osdk/client";
|
|
3
|
+
import type { ModuleConfigTuple } from "./PackApp.js";
|
|
4
|
+
import type { TokenProvider } from "./TokenProvider.js";
|
|
5
|
+
export interface AppConfig {
|
|
6
|
+
readonly app: {
|
|
7
|
+
readonly appId: string;
|
|
8
|
+
readonly appVersion?: string;
|
|
9
|
+
};
|
|
10
|
+
readonly isTestMode: boolean;
|
|
11
|
+
readonly logger: Logger;
|
|
12
|
+
readonly osdkClient: Client;
|
|
13
|
+
readonly remote: {
|
|
14
|
+
readonly packApiPath: string;
|
|
15
|
+
readonly packWsPath: string;
|
|
16
|
+
readonly baseUrl: string;
|
|
17
|
+
readonly fetchFn: typeof globalThis.fetch;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface AppOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Override the authentication token provider from the OSDK client.
|
|
23
|
+
*
|
|
24
|
+
* @default Uses token provider from OSDK client
|
|
25
|
+
*/
|
|
26
|
+
readonly auth?: TokenProvider;
|
|
27
|
+
/**
|
|
28
|
+
* The ID of your application.
|
|
29
|
+
* @default Uses values from page environment meta tags (pack-appId, pack-appVersion)
|
|
30
|
+
*/
|
|
31
|
+
readonly app?: {
|
|
32
|
+
readonly appId: string;
|
|
33
|
+
readonly appVersion?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Logger configuration.
|
|
37
|
+
* @see {@link @osdk/client/internal.BrowserLogger} for a richer console logger.
|
|
38
|
+
* @default Log warnings & errors only.
|
|
39
|
+
*/
|
|
40
|
+
readonly logger?: Logger;
|
|
41
|
+
readonly logLevel?: "debug" | "error" | "info" | "warn";
|
|
42
|
+
/**
|
|
43
|
+
* Internal testing overrides.
|
|
44
|
+
*/
|
|
45
|
+
readonly moduleOverrides?: readonly ModuleConfigTuple[];
|
|
46
|
+
readonly remote?: {
|
|
47
|
+
/**
|
|
48
|
+
* @default "/pack/api"
|
|
49
|
+
*/
|
|
50
|
+
readonly packApiPath?: string;
|
|
51
|
+
/**
|
|
52
|
+
* @default "/pack/ws"
|
|
53
|
+
*/
|
|
54
|
+
readonly packWsPath?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override the base URL from the OSDK client.
|
|
57
|
+
*
|
|
58
|
+
* eg "https://example.com"
|
|
59
|
+
*
|
|
60
|
+
* @default Uses base URL from OSDK client
|
|
61
|
+
*/
|
|
62
|
+
readonly baseUrl?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Override the fetch function from the OSDK client.
|
|
65
|
+
*/
|
|
66
|
+
readonly fetchFn?: typeof globalThis.fetch;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,cAAc;AAC5B,cAAc,cAAc;AAC5B,cAAc,yBAAyB;AACvC,cAAc,qBAAqB;AAEnC,iBAAiB,UAAU;UAChB,KAAK;WACH;WACA;;UAGF;UAEA,QAAQ;UAER,YAAY;UAEZ,QAAQ;WACN;WACA;WACA;WACA,gBAAgB,WAAW;;;AAIxC,iBAAiB,WAAW;;;;;;UAMjB,OAAO;;;;;UAMP,MAAM;WACJ;WACA;;;;;;;UAQF,SAAS;UACT,WAAW,UAAU,UAAU,SAAS;;;;UAKxC,2BAA2B;UAE3B,SAAS;;;;WAIP;;;;WAKA;;;;;;;;WASA;;;;WAKA,iBAAiB,WAAW","names":[],"sources":["../../../src/types/AppConfig.ts"],"version":3,"file":"AppConfig.d.ts"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type Branded<
|
|
2
|
+
Brand extends string,
|
|
3
|
+
T = string
|
|
4
|
+
> = T & Readonly<{
|
|
5
|
+
readonly __pack_brand: Brand;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* A type that is "flavored" for self documenting code and prevents some accidental misuse.
|
|
9
|
+
* This is similar to {@link Branded} but allows implicit use of T without a type assertion,
|
|
10
|
+
* which is useful for stronger typing within certain systems without forcing it for all
|
|
11
|
+
* external uses.
|
|
12
|
+
*
|
|
13
|
+
* Flavored types with different brands will not match.
|
|
14
|
+
* A Branded type with the same brand will implicitly match a Flavored type with the same brand,
|
|
15
|
+
* ie `const foo: Flavored<"foo"> = "foo" as Branded<"foo">`
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* type MyId = Flavored<"MyId">;
|
|
19
|
+
* type OtherId = Flavored<"OtherId">;
|
|
20
|
+
* const id: MyId = "my-id"; // Good: No type assertion needed
|
|
21
|
+
* const otherId: OtherId = id; // Error: Type 'MyId' is not assignable to type 'OtherId'
|
|
22
|
+
* const otherId: OtherId = id as OtherId; // You can assert between flavored types directly
|
|
23
|
+
*/
|
|
24
|
+
export type Flavored<
|
|
25
|
+
Flavor extends string,
|
|
26
|
+
T = string
|
|
27
|
+
> = T & Readonly<{
|
|
28
|
+
readonly __pack_brand?: Flavor;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,YAAY;CAAQ;CAAsB;IACtC,IACA,SAAS;UACA,cAAc;;;;;;;;;;;;;;;;;;;AAoB3B,YAAY;CAAS;CAAuB;IACxC,IACA,SAAS;UACA,eAAe","names":[],"sources":["../../../src/types/Branded.ts"],"version":3,"file":"Branded.d.ts"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PackAppInternal } from "./PackApp.js";
|
|
2
|
+
/**
|
|
3
|
+
* ModuleKey uniquely identifies a module.
|
|
4
|
+
*
|
|
5
|
+
* The key is a symbol and is used to identify the module config.
|
|
6
|
+
* Modules are lazily initialized on first access.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const MY_MODULE_ACCESSOR = "myModule";
|
|
11
|
+
*
|
|
12
|
+
* const MY_MODULE_KEY: ModuleKey<MyModule, MyModuleConfig> = {
|
|
13
|
+
* key: Symbol.for("my.module"),
|
|
14
|
+
*
|
|
15
|
+
* appMemberName: MY_MODULE_ACCESSOR,
|
|
16
|
+
* initModule: initMyModule,
|
|
17
|
+
* };
|
|
18
|
+
*
|
|
19
|
+
* const app = initPackApp({
|
|
20
|
+
* moduleConfig: {
|
|
21
|
+
* [MY_MODULE_KEY.key]: { ... config ... } satisfies MyModuleConfig
|
|
22
|
+
*
|
|
23
|
+
* // Note this is the actual shape of the moduleConfig, ie index by module key symbol
|
|
24
|
+
* // But it is far more ergonomic to spread from a config creator, ie:
|
|
25
|
+
* ...createMyModuleConfig({ ... config ... }),
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // Get the module (manual way)
|
|
30
|
+
* const myModule = app.getModule(MY_MODULE_KEY);
|
|
31
|
+
*
|
|
32
|
+
* // Get the module from app property (available via appMemberName sugar)
|
|
33
|
+
* // You also need to declare the appMemberName on the PackApp interface so the type
|
|
34
|
+
* // system knows it is present. This keeps your module usage limited to where your module
|
|
35
|
+
* // is imported
|
|
36
|
+
* declare module '@palantir/pack.core' {
|
|
37
|
+
* interface PackApp {
|
|
38
|
+
* readonly [MY_MODULE_ACCESSOR]?: MyModule;
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* const myModule = app.myModule;
|
|
42
|
+
*
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface ModuleKey<
|
|
46
|
+
T,
|
|
47
|
+
TConfig = unknown
|
|
48
|
+
> {
|
|
49
|
+
/** If set, this module will have a getter installed on the PackApp interface */
|
|
50
|
+
readonly appMemberName?: string;
|
|
51
|
+
readonly key: symbol;
|
|
52
|
+
readonly initModule: (app: PackAppInternal, config?: TConfig) => T;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAc,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CrC,iBAAiB;CAAU;CAAG;EAAmB;;UAEtC;UACA;UACA,aAAa,KAAK,iBAAiB,SAAS,YAAY","names":[],"sources":["../../../src/types/ModuleKey.ts"],"version":3,"file":"ModuleKey.d.ts"}
|