@parlor/core 0.3.0 → 0.3.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/refresh.d.ts +22 -0
- package/dist/refresh.d.ts.map +1 -0
- package/dist/refresh.js +28 -0
- package/dist/refresh.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { type ActionConfig, type ActionContext, type ActionDefinition, type ActionInput, type ActionMap, type ActionOutput, type ActionSource, type AnyAction, type DataProvider, type DataRegister, type Unlisten, defineAction, isAction, isMutating, type ListenOptions, needsConfirmation, needsPrincipal, type ParlorDatabase, type ReadTags, sourceOfPrincipal, type TableLike, type Tag, type TagSource, } from "./action.js";
|
|
2
|
+
export { decodeReadRequests, encodeReadRequests, MAX_REFRESHED_READS, type ReadRequest, REFRESH_HEADER, type RefreshedRead, } from "./refresh.js";
|
|
2
3
|
export { ACTION_ERROR_CODES, ActionError, type ActionErrorBody, type ActionErrorCode, } from "./errors.js";
|
|
3
4
|
export { asId, type DeviceId, type GrantId, type HostId, type Id, type IdKind, type ItemId, type ThreadId, type TurnId, type UserId, } from "./ids.js";
|
|
4
5
|
export { ANONYMOUS, type AgentIdentity, type AgentPrincipal, type AnonymousPrincipal, type AuthenticatedPrincipal, DEV_USER_ID, type HostPrincipal, isAuthenticated, type Principal, type PrincipalKind, type TurnBinding, type UserPrincipal, userOf, } from "./principal.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,KAAK,aAAa,EAClB,iBAAiB,EACjB,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,EAAE,EACP,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,MAAM,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,WAAW,EACX,KAAK,aAAa,EAClB,eAAe,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,KAAK,aAAa,EAClB,iBAAiB,EACjB,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,GAAG,EACR,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,WAAW,EAChB,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,EAAE,EACP,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,MAAM,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,WAAW,EACX,KAAK,aAAa,EAClB,eAAe,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { defineAction, isAction, isMutating, needsConfirmation, needsPrincipal, sourceOfPrincipal, } from "./action.js";
|
|
2
|
+
export { decodeReadRequests, encodeReadRequests, MAX_REFRESHED_READS, REFRESH_HEADER, } from "./refresh.js";
|
|
2
3
|
export { ACTION_ERROR_CODES, ActionError, } from "./errors.js";
|
|
3
4
|
export { asId, } from "./ids.js";
|
|
4
5
|
export { ANONYMOUS, DEV_USER_ID, isAuthenticated, userOf, } from "./principal.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACZ,QAAQ,EACR,UAAU,EAEV,iBAAiB,EACjB,cAAc,EAGd,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,WAAW,GAGZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,GAUL,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EAKT,WAAW,EAEX,eAAe,EAKf,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export {\n type ActionConfig,\n type ActionContext,\n type ActionDefinition,\n type ActionInput,\n type ActionMap,\n type ActionOutput,\n type ActionSource,\n type AnyAction,\n type DataProvider,\n type DataRegister,\n type Unlisten,\n defineAction,\n isAction,\n isMutating,\n type ListenOptions,\n needsConfirmation,\n needsPrincipal,\n type ParlorDatabase,\n type ReadTags,\n sourceOfPrincipal,\n type TableLike,\n type Tag,\n type TagSource,\n} from \"./action.js\";\nexport {\n ACTION_ERROR_CODES,\n ActionError,\n type ActionErrorBody,\n type ActionErrorCode,\n} from \"./errors.js\";\nexport {\n asId,\n type DeviceId,\n type GrantId,\n type HostId,\n type Id,\n type IdKind,\n type ItemId,\n type ThreadId,\n type TurnId,\n type UserId,\n} from \"./ids.js\";\nexport {\n ANONYMOUS,\n type AgentIdentity,\n type AgentPrincipal,\n type AnonymousPrincipal,\n type AuthenticatedPrincipal,\n DEV_USER_ID,\n type HostPrincipal,\n isAuthenticated,\n type Principal,\n type PrincipalKind,\n type TurnBinding,\n type UserPrincipal,\n userOf,\n} from \"./principal.js\";\nexport { SHELL_ORIGINS } from \"./shell-origins.js\";\nexport { readTagsFor, tableName, tagsOverlap, writeTagsFor } from \"./tags.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACZ,QAAQ,EACR,UAAU,EAEV,iBAAiB,EACjB,cAAc,EAGd,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAEnB,cAAc,GAEf,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,WAAW,GAGZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,GAUL,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EAKT,WAAW,EAEX,eAAe,EAKf,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export {\n type ActionConfig,\n type ActionContext,\n type ActionDefinition,\n type ActionInput,\n type ActionMap,\n type ActionOutput,\n type ActionSource,\n type AnyAction,\n type DataProvider,\n type DataRegister,\n type Unlisten,\n defineAction,\n isAction,\n isMutating,\n type ListenOptions,\n needsConfirmation,\n needsPrincipal,\n type ParlorDatabase,\n type ReadTags,\n sourceOfPrincipal,\n type TableLike,\n type Tag,\n type TagSource,\n} from \"./action.js\";\nexport {\n decodeReadRequests,\n encodeReadRequests,\n MAX_REFRESHED_READS,\n type ReadRequest,\n REFRESH_HEADER,\n type RefreshedRead,\n} from \"./refresh.js\";\nexport {\n ACTION_ERROR_CODES,\n ActionError,\n type ActionErrorBody,\n type ActionErrorCode,\n} from \"./errors.js\";\nexport {\n asId,\n type DeviceId,\n type GrantId,\n type HostId,\n type Id,\n type IdKind,\n type ItemId,\n type ThreadId,\n type TurnId,\n type UserId,\n} from \"./ids.js\";\nexport {\n ANONYMOUS,\n type AgentIdentity,\n type AgentPrincipal,\n type AnonymousPrincipal,\n type AuthenticatedPrincipal,\n DEV_USER_ID,\n type HostPrincipal,\n isAuthenticated,\n type Principal,\n type PrincipalKind,\n type TurnBinding,\n type UserPrincipal,\n userOf,\n} from \"./principal.js\";\nexport { SHELL_ORIGINS } from \"./shell-origins.js\";\nexport { readTagsFor, tableName, tagsOverlap, writeTagsFor } from \"./tags.js\";\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Tag } from "./action.js";
|
|
2
|
+
import type { ActionErrorBody } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Names the reads a page shows on a write it sends, so the answer brings back the ones the
|
|
5
|
+
* write changed and the page needs no second round trip. A header, not part of the body, so
|
|
6
|
+
* a server that does not know it answers the write as always.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REFRESH_HEADER = "x-parlor-refresh";
|
|
9
|
+
/** More is a client gone wrong: each one is a read run with the write. */
|
|
10
|
+
export declare const MAX_REFRESHED_READS = 32;
|
|
11
|
+
/** An action query the page shows: its action and input. */
|
|
12
|
+
export type ReadRequest = readonly [name: string, input: unknown];
|
|
13
|
+
/** A read the write changed, run again after it, or why it could not be; null when the write did not touch it. */
|
|
14
|
+
export type RefreshedRead = {
|
|
15
|
+
readonly data: unknown;
|
|
16
|
+
readonly tags: readonly Tag[];
|
|
17
|
+
readonly cursor?: string;
|
|
18
|
+
} | ActionErrorBody | null;
|
|
19
|
+
export declare function encodeReadRequests(reads: readonly ReadRequest[]): string;
|
|
20
|
+
/** The reads a header names, or undefined for one that is missing or malformed. */
|
|
21
|
+
export declare function decodeReadRequests(header: string | null | undefined): ReadRequest[] | undefined;
|
|
22
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,4DAA4D;AAC5D,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAElE,kHAAkH;AAClH,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnF,eAAe,GACf,IAAI,CAAC;AAET,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAExE;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAChC,WAAW,EAAE,GAAG,SAAS,CAc3B"}
|
package/dist/refresh.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names the reads a page shows on a write it sends, so the answer brings back the ones the
|
|
3
|
+
* write changed and the page needs no second round trip. A header, not part of the body, so
|
|
4
|
+
* a server that does not know it answers the write as always.
|
|
5
|
+
*/
|
|
6
|
+
export const REFRESH_HEADER = "x-parlor-refresh";
|
|
7
|
+
/** More is a client gone wrong: each one is a read run with the write. */
|
|
8
|
+
export const MAX_REFRESHED_READS = 32;
|
|
9
|
+
export function encodeReadRequests(reads) {
|
|
10
|
+
return encodeURIComponent(JSON.stringify(reads));
|
|
11
|
+
}
|
|
12
|
+
/** The reads a header names, or undefined for one that is missing or malformed. */
|
|
13
|
+
export function decodeReadRequests(header) {
|
|
14
|
+
if (!header)
|
|
15
|
+
return undefined;
|
|
16
|
+
let value;
|
|
17
|
+
try {
|
|
18
|
+
value = JSON.parse(decodeURIComponent(header));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(value) || value.length > MAX_REFRESHED_READS)
|
|
24
|
+
return undefined;
|
|
25
|
+
const valid = value.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string");
|
|
26
|
+
return valid ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.js","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEjD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAWtC,MAAM,UAAU,kBAAkB,CAAC,KAA6B;IAC9D,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAChC,MAAiC;IAEjC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,mBAAmB;QAAE,OAAO,SAAS,CAAC;IAClF,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CACvB,CAAC,KAAK,EAAwB,EAAE,CAC9B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAC7E,CAAC;IACF,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACnC,CAAC","sourcesContent":["import type { Tag } from \"./action.js\";\nimport type { ActionErrorBody } from \"./errors.js\";\n\n/**\n * Names the reads a page shows on a write it sends, so the answer brings back the ones the\n * write changed and the page needs no second round trip. A header, not part of the body, so\n * a server that does not know it answers the write as always.\n */\nexport const REFRESH_HEADER = \"x-parlor-refresh\";\n\n/** More is a client gone wrong: each one is a read run with the write. */\nexport const MAX_REFRESHED_READS = 32;\n\n/** An action query the page shows: its action and input. */\nexport type ReadRequest = readonly [name: string, input: unknown];\n\n/** A read the write changed, run again after it, or why it could not be; null when the write did not touch it. */\nexport type RefreshedRead =\n | { readonly data: unknown; readonly tags: readonly Tag[]; readonly cursor?: string }\n | ActionErrorBody\n | null;\n\nexport function encodeReadRequests(reads: readonly ReadRequest[]): string {\n return encodeURIComponent(JSON.stringify(reads));\n}\n\n/** The reads a header names, or undefined for one that is missing or malformed. */\nexport function decodeReadRequests(\n header: string | null | undefined,\n): ReadRequest[] | undefined {\n if (!header) return undefined;\n let value: unknown;\n try {\n value = JSON.parse(decodeURIComponent(header));\n } catch {\n return undefined;\n }\n if (!Array.isArray(value) || value.length > MAX_REFRESHED_READS) return undefined;\n const valid = value.every(\n (entry): entry is ReadRequest =>\n Array.isArray(entry) && entry.length === 2 && typeof entry[0] === \"string\",\n );\n return valid ? value : undefined;\n}\n"]}
|