lucid-extension-sdk 0.0.441 → 0.0.442

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.
Files changed (45) hide show
  1. package/commandtypes.d.ts +4 -0
  2. package/core/cardintegration/cardfielddisplaysettings.d.ts +6 -1
  3. package/core/cardintegration/cardfielddisplaysettings.js +5 -0
  4. package/core/cardintegration/cardpaneltabs/tab.d.ts +23 -0
  5. package/core/cardintegration/cardpaneltabs/tab.js +30 -0
  6. package/core/cardintegration/cardpaneltabs/tabs/listtab.d.ts +29 -0
  7. package/core/cardintegration/cardpaneltabs/tabs/listtab.js +31 -0
  8. package/core/cardintegration/cardpaneltabs/tabs.d.ts +37 -0
  9. package/core/cardintegration/cardpaneltabs/tabs.js +60 -0
  10. package/core/cardintegration/lucidcardintegration.d.ts +6 -0
  11. package/core/cardintegration/lucidcardintegrationregistry.js +14 -0
  12. package/core/cardintegration/useritemeditpermissions.d.ts +2 -2
  13. package/core/cardintegration/useritemeditpermissions.js +1 -1
  14. package/core/enum.d.ts +26 -0
  15. package/core/enum.js +46 -0
  16. package/core/identity.d.ts +11 -0
  17. package/core/identity.js +20 -0
  18. package/core/iterable.d.ts +22 -0
  19. package/core/iterable.js +63 -0
  20. package/core/map.d.ts +22 -0
  21. package/core/map.js +51 -0
  22. package/core/maybepartialrecord.d.ts +12 -0
  23. package/core/maybepartialrecord.js +2 -0
  24. package/core/opaque.d.ts +24 -0
  25. package/core/opaque.js +17 -0
  26. package/core/prettify.d.ts +6 -0
  27. package/core/prettify.js +2 -0
  28. package/core/primitivedata.d.ts +37 -0
  29. package/core/primitivedata.js +109 -0
  30. package/core/properties/datagraphic/datagraphicindexes.d.ts +1 -1
  31. package/core/publicinterface.d.ts +12 -0
  32. package/core/publicinterface.js +2 -0
  33. package/core/sharedcardintegration/cardintegrationdefinitions.d.ts +75 -14
  34. package/core/sharedcardintegration/cardintegrationdefinitions.js +30 -14
  35. package/data/patcherrortype.d.ts +7 -0
  36. package/data/patcherrortype.js +11 -0
  37. package/dataconnector/actions/patchresponsebody.d.ts +10 -5
  38. package/dataconnector/actions/patchresponsebody.js +9 -8
  39. package/editorclient.d.ts +6 -0
  40. package/index.d.ts +3 -0
  41. package/index.js +3 -0
  42. package/math.d.ts +10 -1
  43. package/math.js +8 -1
  44. package/object.d.ts +15 -0
  45. package/package.json +1 -1
package/commandtypes.d.ts CHANGED
@@ -784,6 +784,8 @@ export type SerializedFieldConfiguration = {
784
784
  'cfds'?: SerializedCustomFieldDisplaySettings;
785
785
  /** Non-customizable fields */
786
786
  'ncf'?: string[] | undefined;
787
+ /** Callback to get fields to edit related to a field passed as an argument */
788
+ 'gfte'?: string | undefined;
787
789
  };
788
790
  export type AddCardIntegrationQuery = {
789
791
  /** Title/name */
@@ -933,6 +935,8 @@ export type AddCardIntegrationQuery = {
933
935
  * Whether the user can edit an item in the data source.
934
936
  */
935
937
  'cei'?: string | undefined;
938
+ /** getAdditionalPanelTabsForCard -- Cards' additional details via tabs in panel */
939
+ 'gaptfc'?: string | undefined;
936
940
  };
937
941
  export type AddCardIntegrationResult = undefined;
938
942
  /** @ignore */
@@ -86,7 +86,12 @@ export declare enum OnClickHandlerKeys {
86
86
  * Display a panel on the canvas when a stencil is clicked, showing editable input fields for the values that
87
87
  * calculate what is shown on the stencil
88
88
  */
89
- EditFieldsStencilPanel = "EditFieldsStencilPanel"
89
+ EditFieldsStencilPanel = "EditFieldsStencilPanel",
90
+ /**
91
+ * Display a panel on the canvas when a stencil is clicked, showing editable input fields for the values that
92
+ * calculate what is shown on the stencil
93
+ */
94
+ DataRowStencilPanel = "DataRowStencilPanel"
90
95
  }
91
96
  export declare const isOnClickHandlerKey: (x: unknown) => x is OnClickHandlerKeys;
92
97
  export type ImageBadgeSettings = {
@@ -93,6 +93,11 @@ var OnClickHandlerKeys;
93
93
  * calculate what is shown on the stencil
94
94
  */
95
95
  OnClickHandlerKeys["EditFieldsStencilPanel"] = "EditFieldsStencilPanel";
96
+ /**
97
+ * Display a panel on the canvas when a stencil is clicked, showing editable input fields for the values that
98
+ * calculate what is shown on the stencil
99
+ */
100
+ OnClickHandlerKeys["DataRowStencilPanel"] = "DataRowStencilPanel";
96
101
  })(OnClickHandlerKeys || (exports.OnClickHandlerKeys = OnClickHandlerKeys = {}));
97
102
  exports.isOnClickHandlerKey = (0, validators_1.enumValidator)(OnClickHandlerKeys);
98
103
  const isImageBadgeSettings = (0, validators_1.objectValidator)({
@@ -0,0 +1,23 @@
1
+ import { LucidCardPanelListTab, SerializedLucidCardPanelListTab } from './tabs/listtab';
2
+ /**
3
+ * @experimental Information to represent a tab, in the card details panel.
4
+ * There exist various kinds of tabs in the panel.
5
+ * Each kind has its own corresponding information and type definition, found in the `tabs` subdirectory.
6
+ */
7
+ export type LucidCardPanelTab = LucidCardPanelListTab;
8
+ /** @ignore */
9
+ export declare const isValidLucidCardPanelTab: (x: any) => x is import("../../guards").DestructureGuardedTypeObj<{
10
+ type: (x: unknown) => x is "LucidCardPanelListTab";
11
+ label: typeof import("../../checks").isString;
12
+ }>;
13
+ /** @ignore */
14
+ export type SerializedLucidCardPanelTab = SerializedLucidCardPanelListTab;
15
+ /** @ignore */
16
+ export declare const isValidSerializedLucidCardPanelTab: (x: any) => x is import("../../guards").DestructureGuardedTypeObj<{
17
+ type: (x: unknown) => x is "lcplt";
18
+ l: typeof import("../../checks").isString;
19
+ }>;
20
+ /** @ignore */
21
+ export declare function serializeLucidCardPanelTab(concrete: LucidCardPanelTab): SerializedLucidCardPanelTab;
22
+ /** @ignore */
23
+ export declare function deserializeLucidCardPanelTab(serialized: SerializedLucidCardPanelTab): LucidCardPanelTab;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeLucidCardPanelTab = exports.serializeLucidCardPanelTab = exports.isValidSerializedLucidCardPanelTab = exports.isValidLucidCardPanelTab = void 0;
4
+ const assertnever_1 = require("../../assertnever");
5
+ const validators_1 = require("../../validators/validators");
6
+ const listtab_1 = require("./tabs/listtab");
7
+ /** @ignore */
8
+ exports.isValidLucidCardPanelTab = (0, validators_1.someValidator)(listtab_1.isValidLucidCardPanelListTab);
9
+ /** @ignore */
10
+ exports.isValidSerializedLucidCardPanelTab = (0, validators_1.someValidator)(listtab_1.isValidSerializedLucidCardPanelListTab);
11
+ /** @ignore */
12
+ function serializeLucidCardPanelTab(concrete) {
13
+ switch (concrete.type) {
14
+ case 'LucidCardPanelListTab':
15
+ return (0, listtab_1.serializeLucidCardPanelListTab)(concrete);
16
+ default:
17
+ (0, assertnever_1.assertNever)(concrete.type);
18
+ }
19
+ }
20
+ exports.serializeLucidCardPanelTab = serializeLucidCardPanelTab;
21
+ /** @ignore */
22
+ function deserializeLucidCardPanelTab(serialized) {
23
+ switch (serialized.type) {
24
+ case 'lcplt':
25
+ return (0, listtab_1.deserializeLucidCardPanelListTab)(serialized);
26
+ default:
27
+ (0, assertnever_1.assertNever)(serialized.type);
28
+ }
29
+ }
30
+ exports.deserializeLucidCardPanelTab = deserializeLucidCardPanelTab;
@@ -0,0 +1,29 @@
1
+ import { isString } from '../../../checks';
2
+ /**
3
+ * @ignore Will be implemented soon.
4
+ * Information that represents a list of items.
5
+ * (Currently blank and unimplemented.)
6
+ */
7
+ export interface LucidCardPanelListTab {
8
+ type: 'LucidCardPanelListTab';
9
+ label: string;
10
+ }
11
+ /** @ignore */
12
+ export declare const isValidLucidCardPanelListTab: (subject: unknown) => subject is import("../../../guards").DestructureGuardedTypeObj<{
13
+ type: (x: unknown) => x is "LucidCardPanelListTab";
14
+ label: typeof isString;
15
+ }>;
16
+ /** @ignore */
17
+ export interface SerializedLucidCardPanelListTab {
18
+ 'type': 'lcplt';
19
+ 'l': string;
20
+ }
21
+ /** @ignore */
22
+ export declare const isValidSerializedLucidCardPanelListTab: (subject: unknown) => subject is import("../../../guards").DestructureGuardedTypeObj<{
23
+ type: (x: unknown) => x is "lcplt";
24
+ l: typeof isString;
25
+ }>;
26
+ /** @ignore */
27
+ export declare function serializeLucidCardPanelListTab(concrete: LucidCardPanelListTab): SerializedLucidCardPanelListTab;
28
+ /** @ignore */
29
+ export declare function deserializeLucidCardPanelListTab(serialized: SerializedLucidCardPanelListTab): LucidCardPanelListTab;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeLucidCardPanelListTab = exports.serializeLucidCardPanelListTab = exports.isValidSerializedLucidCardPanelListTab = exports.isValidLucidCardPanelListTab = void 0;
4
+ const checks_1 = require("../../../checks");
5
+ const validators_1 = require("../../../validators/validators");
6
+ /** @ignore */
7
+ exports.isValidLucidCardPanelListTab = (0, validators_1.objectValidator)({
8
+ type: (0, validators_1.someValue)('LucidCardPanelListTab'),
9
+ label: checks_1.isString,
10
+ });
11
+ /** @ignore */
12
+ exports.isValidSerializedLucidCardPanelListTab = (0, validators_1.objectValidator)({
13
+ 'type': (0, validators_1.someValue)('lcplt'),
14
+ 'l': checks_1.isString,
15
+ });
16
+ /** @ignore */
17
+ function serializeLucidCardPanelListTab(concrete) {
18
+ return {
19
+ 'type': 'lcplt',
20
+ 'l': concrete.label,
21
+ };
22
+ }
23
+ exports.serializeLucidCardPanelListTab = serializeLucidCardPanelListTab;
24
+ /** @ignore */
25
+ function deserializeLucidCardPanelListTab(serialized) {
26
+ return {
27
+ type: 'LucidCardPanelListTab',
28
+ label: serialized['l'],
29
+ };
30
+ }
31
+ exports.deserializeLucidCardPanelListTab = deserializeLucidCardPanelListTab;
@@ -0,0 +1,37 @@
1
+ import { AddCardIntegrationQuery } from '../../../commandtypes';
2
+ import { DataItemProxy } from '../../../data/dataitemproxy';
3
+ import { EditorClient, PostMessageType } from '../../../editorclient';
4
+ import { DataItemCallbackParam } from '../cardintegrationparams';
5
+ import { LucidCardPanelTab, SerializedLucidCardPanelTab } from './tab';
6
+ /**
7
+ * @experimental Information to represent a collection of tabs, in the card details panel.
8
+ */
9
+ export type LucidCardPanelTabs = LucidCardPanelTab[];
10
+ /** @ignore */
11
+ export declare const areValidLucidCardPanelTabs: (p1: unknown) => p1 is import("../../guards").DestructureGuardedTypeObj<{
12
+ type: (x: unknown) => x is "LucidCardPanelListTab";
13
+ label: typeof import("../../checks").isString;
14
+ }>[];
15
+ /** @ignore */
16
+ export type SerializedLucidCardPanelTabs = SerializedLucidCardPanelTab[];
17
+ /** @ignore */
18
+ export declare const areValidSerializedLucidCardPanelTabs: (p1: unknown) => p1 is import("../../guards").DestructureGuardedTypeObj<{
19
+ type: (x: unknown) => x is "lcplt";
20
+ l: typeof import("../../checks").isString;
21
+ }>[];
22
+ /** @ignore */
23
+ export declare function serializeLucidCardPanelTabs(concrete: LucidCardPanelTabs): SerializedLucidCardPanelTabs;
24
+ /** @ignore */
25
+ export declare function deserializeLucidCardPanelTabs(serialized: SerializedLucidCardPanelTabs): LucidCardPanelTabs;
26
+ /**
27
+ * @experimental Callback function that, from a data item, derives additional tabs to show in the card details panel.
28
+ */
29
+ export type AdditionalPanelTabsCallback = (dataItemProxy: DataItemProxy) => Promise<LucidCardPanelTabs | undefined>;
30
+ /** @ignore */
31
+ export type AdditionalPanelTabsCallbackInternal = (dataItemCallbackParam: DataItemCallbackParam) => Promise<SerializedLucidCardPanelTabs | undefined>;
32
+ /** @ignore */
33
+ export declare function registerGetAdditionalPanelTabsForCardCallback(client: EditorClient, tabsCallback: AdditionalPanelTabsCallback, serialized: AddCardIntegrationQuery, actionName: string): void;
34
+ /** @ignore */
35
+ export type TabsCallbackInternal = (dataSourceId: string, collectionId: string, primaryKey: string) => Promise<LucidCardPanelTabs | undefined>;
36
+ /** @ignore */
37
+ export declare function deserializeTabsCallback(callbackHookName: string, postMessage: PostMessageType): TabsCallbackInternal;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeTabsCallback = exports.registerGetAdditionalPanelTabsForCardCallback = exports.deserializeLucidCardPanelTabs = exports.serializeLucidCardPanelTabs = exports.areValidSerializedLucidCardPanelTabs = exports.areValidLucidCardPanelTabs = void 0;
4
+ const collectionproxy_1 = require("../../../data/collectionproxy");
5
+ const dataitemproxy_1 = require("../../../data/dataitemproxy");
6
+ const validators_1 = require("../../validators/validators");
7
+ const tab_1 = require("./tab");
8
+ /** @ignore */
9
+ exports.areValidLucidCardPanelTabs = (0, validators_1.arrayValidator)(tab_1.isValidLucidCardPanelTab);
10
+ /** @ignore */
11
+ exports.areValidSerializedLucidCardPanelTabs = (0, validators_1.arrayValidator)(tab_1.isValidSerializedLucidCardPanelTab);
12
+ /** @ignore */
13
+ function serializeLucidCardPanelTabs(concrete) {
14
+ return concrete.map(tab_1.serializeLucidCardPanelTab);
15
+ }
16
+ exports.serializeLucidCardPanelTabs = serializeLucidCardPanelTabs;
17
+ /** @ignore */
18
+ function deserializeLucidCardPanelTabs(serialized) {
19
+ return serialized.map(tab_1.deserializeLucidCardPanelTab);
20
+ }
21
+ exports.deserializeLucidCardPanelTabs = deserializeLucidCardPanelTabs;
22
+ /** @ignore */
23
+ function registerGetAdditionalPanelTabsForCardCallback(client, tabsCallback, serialized, actionName) {
24
+ serialized['gaptfc'] = actionName;
25
+ const serializedAction = async ({ 'd': dataSourceId, 'c': collectionId, 'p': primaryKey, }) => {
26
+ try {
27
+ const collectionProxy = new collectionproxy_1.CollectionProxy(collectionId, client);
28
+ const dataItemProxy = new dataitemproxy_1.DataItemProxy(primaryKey, collectionProxy, client);
29
+ const result = await tabsCallback(dataItemProxy);
30
+ if (result === undefined) {
31
+ return undefined;
32
+ }
33
+ return serializeLucidCardPanelTabs(result);
34
+ }
35
+ catch (err) {
36
+ return undefined;
37
+ }
38
+ };
39
+ client.registerAction(actionName, serializedAction);
40
+ }
41
+ exports.registerGetAdditionalPanelTabsForCardCallback = registerGetAdditionalPanelTabsForCardCallback;
42
+ /** @ignore */
43
+ function deserializeTabsCallback(callbackHookName, postMessage) {
44
+ // Serializes, runs callback, and deserializes the result
45
+ const wrappedCallback = async (dataSourceId, collectionId, primaryKey) => {
46
+ const callbackParam = {
47
+ 'd': dataSourceId,
48
+ 'c': collectionId,
49
+ 'p': primaryKey,
50
+ };
51
+ const serializedTabs = await postMessage(Object.assign({ 'id': callbackHookName }, callbackParam));
52
+ if (!(0, exports.areValidSerializedLucidCardPanelTabs)(serializedTabs)) {
53
+ return undefined;
54
+ }
55
+ const result = deserializeLucidCardPanelTabs(serializedTabs);
56
+ return result;
57
+ };
58
+ return wrappedCallback;
59
+ }
60
+ exports.deserializeTabsCallback = deserializeTabsCallback;
@@ -10,6 +10,7 @@ import { ImportCardFromPastedLinkCallback } from '../importcardfrompastedlink/im
10
10
  import { DependenciesForItems, ExtensionCardFieldDefinition, ExtensionFieldConfiguration, ImportResult } from '../sharedcardintegration/cardintegrationdefinitions';
11
11
  import { CardIntegrationAutoSyncConfig } from './cardintegrationautosyncconfig';
12
12
  import { CardIntegrationConfig } from './cardintegrationconfig';
13
+ import { AdditionalPanelTabsCallback } from './cardpaneltabs/tabs';
13
14
  import { DependencyMappingPhrasesType } from './dependencymappingphrases';
14
15
  import { LucidCardIntegrationCustomImportModal } from './lucidcardintegrationcustomimportmodal';
15
16
  import { LucidCardIntegrationStandardImportModal } from './lucidcardintegrationstandardimportmodal';
@@ -161,4 +162,9 @@ export declare abstract class LucidCardIntegration {
161
162
  * Returns a Map with per-item permission results, keyed by item primary key.
162
163
  */
163
164
  canEditItems?: (items: DataItemProxy[]) => Promise<Map<string, UserItemEditPermissions>>;
165
+ /**
166
+ * @experimental If specified, allows for cards to display additional details,
167
+ * via tabs that are configured by the extension and displayed in the card details panel.
168
+ */
169
+ getAdditionalPanelTabsForCard?: AdditionalPanelTabsCallback;
164
170
  }
@@ -11,6 +11,7 @@ const importcardfromdetails_1 = require("../importcardfromdetails/importcardfrom
11
11
  const cardintegrationdefinitions_1 = require("../sharedcardintegration/cardintegrationdefinitions");
12
12
  const cardintegrationautosyncconfig_1 = require("./cardintegrationautosyncconfig");
13
13
  const cardintegrationconfig_1 = require("./cardintegrationconfig");
14
+ const tabs_1 = require("./cardpaneltabs/tabs");
14
15
  const lucidcardintegrationcustomimportmodal_1 = require("./lucidcardintegrationcustomimportmodal");
15
16
  const useritemeditpermissions_1 = require("./useritemeditpermissions");
16
17
  class LucidCardIntegrationRegistry {
@@ -258,6 +259,14 @@ class LucidCardIntegrationRegistry {
258
259
  const dataSource = new datasourceproxy_1.DataSourceProxy(param['d'], client);
259
260
  return (0, cardintegrationconfig_1.serializeCardIntegrationConfig)(await cardIntegration.getDefaultConfig(dataSource));
260
261
  });
262
+ let getFieldsToEditActionName = undefined;
263
+ const getFieldsToEdit = cardIntegration.fieldConfiguration.getFieldsToEdit;
264
+ if (getFieldsToEdit) {
265
+ getFieldsToEditActionName = LucidCardIntegrationRegistry.nextHookName();
266
+ client.registerAction(getFieldsToEditActionName, async ({ 'f': fieldId }) => {
267
+ return (0, cardintegrationdefinitions_1.serializeExtensionCardFieldsGroupArray)(await getFieldsToEdit(fieldId));
268
+ });
269
+ }
261
270
  let showIntroActionName = undefined;
262
271
  if (cardIntegration.showIntro) {
263
272
  showIntroActionName = LucidCardIntegrationRegistry.nextHookName();
@@ -278,6 +287,7 @@ class LucidCardIntegrationRegistry {
278
287
  ? [...cardIntegration.fieldConfiguration.fieldValueSearchCallbacks.entries()]
279
288
  : undefined,
280
289
  'dsc': cardIntegration.fieldConfiguration.defaultSearchCallback,
290
+ 'gfte': getFieldsToEditActionName,
281
291
  },
282
292
  'subn': cardIntegration.searchUserByName,
283
293
  'usc': cardIntegration.userSearchCallback,
@@ -455,6 +465,10 @@ class LucidCardIntegrationRegistry {
455
465
  }
456
466
  this.registerDependencyMapping(client, cardIntegration, serialized);
457
467
  this.registerImportCardFromPastedLinkHandler(client, cardIntegration, serialized);
468
+ if (cardIntegration.getAdditionalPanelTabsForCard) {
469
+ const actionName = LucidCardIntegrationRegistry.nextHookName();
470
+ (0, tabs_1.registerGetAdditionalPanelTabsForCardCallback)(client, cardIntegration.getAdditionalPanelTabsForCard, serialized, actionName);
471
+ }
458
472
  if (cardIntegration.importFromSerializedFields) {
459
473
  const importFromSerializedFields = cardIntegration.importFromSerializedFields;
460
474
  serialized['ifs'] = LucidCardIntegrationRegistry.nextHookName();
@@ -6,7 +6,7 @@ export interface UserItemEditPermissions {
6
6
  hasPermission: boolean;
7
7
  constraints: {
8
8
  fieldName: string;
9
- constraints?: SerializedFieldConstraint[];
9
+ constraints: SerializedFieldConstraint[];
10
10
  }[];
11
11
  }
12
12
  export declare class UserCanEditItem implements UserItemEditPermissions {
@@ -21,7 +21,7 @@ export interface SerializedUserItemEditPermissions {
21
21
  'hp': boolean;
22
22
  'c': {
23
23
  'fn': string;
24
- 'cs': SerializedFieldConstraint[] | undefined;
24
+ 'cs': SerializedFieldConstraint[];
25
25
  }[];
26
26
  }
27
27
  export declare function serializeUserItemEditPermissionsMap(map: Map<string, UserItemEditPermissions>): Record<string, SerializedUserItemEditPermissions>;
@@ -22,7 +22,7 @@ const isSerializedUserItemEditPermissions = (0, validators_1.objectValidator)({
22
22
  'hp': checks_1.isBoolean,
23
23
  'c': (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
24
24
  'fn': checks_1.isString,
25
- 'cs': (0, validators_1.option)((0, validators_1.arrayValidator)(serializedfielddefinition_1.isSerializedFieldConstraint)),
25
+ 'cs': (0, validators_1.arrayValidator)(serializedfielddefinition_1.isSerializedFieldConstraint),
26
26
  })),
27
27
  });
28
28
  function serializeUserItemEditPermissions(result) {
package/core/enum.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
3
+ * This works because as of TS 2.5 enums can't have number keys.
4
+ */
5
+ export declare function getEnumValues<T extends object>(enumObj: T): keyof T extends never ? [] : T[keyof T][];
6
+ /**
7
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
8
+ * This works because as of TS 2.5 enums can't have number keys.
9
+ */
10
+ export declare function getEnumKeys<T extends object>(enumObj: T): (keyof T)[];
11
+ /**
12
+ * Returns all real entries of enum. That is, removes the reverse-map entries that TS adds
13
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
14
+ * This works because as of TS 2.5 enums can't have number keys.
15
+ */
16
+ export declare function getRealEnumEntries<T extends object>(enumObj: T): [keyof T, T[keyof T]][];
17
+ /**
18
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
19
+ * This works because as of TS 2.5 enums can't have number keys.
20
+ */
21
+ export declare function isEnumValue<T extends object>(value: any, enumObj: T): value is T[keyof T];
22
+ /**
23
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
24
+ * This works because as of TS 2.5 enums can't have number keys.
25
+ */
26
+ export declare function asEnumValue<T extends object>(value: unknown, enumObj: T): T[keyof T] | undefined;
package/core/enum.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asEnumValue = exports.isEnumValue = exports.getRealEnumEntries = exports.getEnumKeys = exports.getEnumValues = void 0;
4
+ /**
5
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
6
+ * This works because as of TS 2.5 enums can't have number keys.
7
+ */
8
+ function getEnumValues(enumObj) {
9
+ return getRealEnumEntries(enumObj).map((e) => e[1]);
10
+ }
11
+ exports.getEnumValues = getEnumValues;
12
+ /**
13
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
14
+ * This works because as of TS 2.5 enums can't have number keys.
15
+ */
16
+ function getEnumKeys(enumObj) {
17
+ return getRealEnumEntries(enumObj).map((e) => e[0]);
18
+ }
19
+ exports.getEnumKeys = getEnumKeys;
20
+ /**
21
+ * Returns all real entries of enum. That is, removes the reverse-map entries that TS adds
22
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
23
+ * This works because as of TS 2.5 enums can't have number keys.
24
+ */
25
+ function getRealEnumEntries(enumObj) {
26
+ return Object.keys(enumObj)
27
+ .map((key) => [key, enumObj[key]])
28
+ .filter(([key, value]) => value === key || enumObj[value] != key || typeof value == 'number');
29
+ }
30
+ exports.getRealEnumEntries = getRealEnumEntries;
31
+ /**
32
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
33
+ * This works because as of TS 2.5 enums can't have number keys.
34
+ */
35
+ function isEnumValue(value, enumObj) {
36
+ return getEnumValues(enumObj).includes(value);
37
+ }
38
+ exports.isEnumValue = isEnumValue;
39
+ /**
40
+ * Note, this will NOT work for const enums, as const enums are compiled out!!
41
+ * This works because as of TS 2.5 enums can't have number keys.
42
+ */
43
+ function asEnumValue(value, enumObj) {
44
+ return isEnumValue(value, enumObj) ? value : undefined;
45
+ }
46
+ exports.asEnumValue = asEnumValue;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Adapted from https://google.github.io/closure-library/api/goog.functions.html#identity
3
+ *
4
+ * A simple function that returns the first argument of whatever is passed
5
+ * into it.
6
+ * @param opt_returnValue The single value that will be returned.
7
+ * @param var_args Optional trailing arguments. These are ignored.
8
+ * @return The first argument passed in, or undefined if nothing was passed.
9
+ * @template T
10
+ */
11
+ export declare const identity: <T>(opt_returnValue?: T | undefined, ...var_args: any[]) => T;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.identity = void 0;
4
+ /**
5
+ * Adapted from https://google.github.io/closure-library/api/goog.functions.html#identity
6
+ *
7
+ * A simple function that returns the first argument of whatever is passed
8
+ * into it.
9
+ * @param opt_returnValue The single value that will be returned.
10
+ * @param var_args Optional trailing arguments. These are ignored.
11
+ * @return The first argument passed in, or undefined if nothing was passed.
12
+ * @template T
13
+ */
14
+ const identity = function (opt_returnValue, ...var_args) {
15
+ // This non-null assertion is needed to maintain the behavior inherited from the closure library implementation
16
+ // (specifically, the fact that library has a JS implementation which means we don't quite have the same types to
17
+ // line up).
18
+ return opt_returnValue;
19
+ };
20
+ exports.identity = identity;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Retrieves and consumes the first value from an iterator.
3
+ * Useful because most iterators don't track their return type, because it is usually undefined, but the default is any.
4
+ */
5
+ export declare function consumeFirstValue<N>(iterator: Iterator<N, undefined | void>): N | undefined;
6
+ /**
7
+ * Merges multiple generator functions into a single generator that yields all values sequentially.
8
+ * Each generator function will be called and its values yielded in the order provided.
9
+ */
10
+ export declare function mergeGenerators<T>(...generatorFunctions: (() => Iterable<T>)[]): () => Generator<T, void, undefined>;
11
+ /**
12
+ * Zips an object of iterables, shorter iterables will simply repeat the last value.
13
+ * For example:
14
+ * {a: [1, 2], b: [1,2,3]} will return [{a: 1, b: 1}, {a: 2, b: 2}, {a: 2, b: 3}]
15
+ *
16
+ * Assumes that no iterables are empty
17
+ */
18
+ export declare function zipHoldShorter<T extends {
19
+ [key: string]: Iterable<unknown>;
20
+ }>(obj: T): Iterable<{
21
+ [key in keyof T]-?: T[key] extends Iterable<infer U> ? U : never;
22
+ }>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zipHoldShorter = exports.mergeGenerators = exports.consumeFirstValue = void 0;
4
+ /**
5
+ * Retrieves and consumes the first value from an iterator.
6
+ * Useful because most iterators don't track their return type, because it is usually undefined, but the default is any.
7
+ */
8
+ function consumeFirstValue(iterator) {
9
+ return iterator.next().value;
10
+ }
11
+ exports.consumeFirstValue = consumeFirstValue;
12
+ /**
13
+ * Merges multiple generator functions into a single generator that yields all values sequentially.
14
+ * Each generator function will be called and its values yielded in the order provided.
15
+ */
16
+ function mergeGenerators(...generatorFunctions) {
17
+ return function* () {
18
+ for (const generatorFunction of generatorFunctions) {
19
+ yield* generatorFunction();
20
+ }
21
+ };
22
+ }
23
+ exports.mergeGenerators = mergeGenerators;
24
+ /**
25
+ * Zips an object of iterables, shorter iterables will simply repeat the last value.
26
+ * For example:
27
+ * {a: [1, 2], b: [1,2,3]} will return [{a: 1, b: 1}, {a: 2, b: 2}, {a: 2, b: 3}]
28
+ *
29
+ * Assumes that no iterables are empty
30
+ */
31
+ function* zipHoldShorter(obj) {
32
+ const unheldKeys = new Set(Object.keys(obj));
33
+ const iterators = {};
34
+ for (const key of unheldKeys) {
35
+ const value = obj[key];
36
+ //Please note these keys are retrieved from obj directly. So this should never be entered barring some strange edge case.
37
+ if (value === undefined) {
38
+ continue;
39
+ }
40
+ iterators[key] = value[Symbol.iterator]();
41
+ }
42
+ const heldValues = {};
43
+ let previous = {};
44
+ while (unheldKeys.size > 0) {
45
+ const zipped = Object.assign({}, heldValues);
46
+ for (const key of unheldKeys) {
47
+ const result = iterators[key].next();
48
+ if (result.done) {
49
+ heldValues[key] = previous[key];
50
+ unheldKeys.delete(key);
51
+ zipped[key] = heldValues[key];
52
+ }
53
+ else {
54
+ zipped[key] = result.value;
55
+ }
56
+ }
57
+ previous = zipped;
58
+ if (unheldKeys.size > 0) {
59
+ yield zipped;
60
+ }
61
+ }
62
+ }
63
+ exports.zipHoldShorter = zipHoldShorter;
package/core/map.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A Map that automatically creates values for missing keys using a provided getter function.
3
+ * Extends the standard Map with automatic value generation on access.
4
+ */
5
+ export declare class DefaultMap<K, V> extends Map<K, V> {
6
+ private readonly defaultGetter;
7
+ get(key: K): V;
8
+ getIfHas(key: K): V | undefined;
9
+ constructor(defaultGetter: (key: K) => V, iterable?: Iterable<readonly [K, V]> | null);
10
+ }
11
+ /**
12
+ * A WeakMap that automatically creates values for missing keys using a default getter function.
13
+ * Extends the standard WeakMap with automatic value generation on access.
14
+ */
15
+ export declare class DefaultWeakMap<K extends object, V> extends WeakMap<K, V> {
16
+ private readonly defaultGetter;
17
+ get(key: K): V;
18
+ getIfHas(key: K): V | undefined;
19
+ constructor(defaultGetter: (key: K) => V);
20
+ }
21
+ export declare function toRecord<K extends string | number, V>(map: ReadonlyMap<K, V>): Partial<Record<K, V>>;
22
+ export declare function toNonPartialRecord<K extends string | number, V>(map: ReadonlyMap<K, V>): Record<K, V>;
package/core/map.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNonPartialRecord = exports.toRecord = exports.DefaultWeakMap = exports.DefaultMap = void 0;
4
+ /**
5
+ * A Map that automatically creates values for missing keys using a provided getter function.
6
+ * Extends the standard Map with automatic value generation on access.
7
+ */
8
+ class DefaultMap extends Map {
9
+ get(key) {
10
+ if (!this.has(key)) {
11
+ this.set(key, this.defaultGetter(key));
12
+ }
13
+ return super.get(key);
14
+ }
15
+ getIfHas(key) {
16
+ return super.get(key);
17
+ }
18
+ constructor(defaultGetter, iterable) {
19
+ super(iterable);
20
+ this.defaultGetter = defaultGetter;
21
+ }
22
+ }
23
+ exports.DefaultMap = DefaultMap;
24
+ /**
25
+ * A WeakMap that automatically creates values for missing keys using a default getter function.
26
+ * Extends the standard WeakMap with automatic value generation on access.
27
+ */
28
+ class DefaultWeakMap extends WeakMap {
29
+ get(key) {
30
+ if (!this.has(key)) {
31
+ this.set(key, this.defaultGetter(key));
32
+ }
33
+ return super.get(key);
34
+ }
35
+ getIfHas(key) {
36
+ return super.get(key);
37
+ }
38
+ constructor(defaultGetter) {
39
+ super();
40
+ this.defaultGetter = defaultGetter;
41
+ }
42
+ }
43
+ exports.DefaultWeakMap = DefaultWeakMap;
44
+ function toRecord(map) {
45
+ return Object.fromEntries(map.entries());
46
+ }
47
+ exports.toRecord = toRecord;
48
+ function toNonPartialRecord(map) {
49
+ return Object.fromEntries(map.entries());
50
+ }
51
+ exports.toNonPartialRecord = toNonPartialRecord;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Note that the intended use of this method is only to handle `Record<string, V>`, not `Record<number, V>`. Using a
3
+ * number key is not supported here because this utility is meant to only represent records that are both valid
4
+ * JavaScript and valid JSON (and, number keys are not valid in JSON).
5
+ */
6
+ export type MaybePartialRecord<K extends string | number, V> = string extends K ? Record<K, V> : Partial<Record<K, V>>;
7
+ /** @see {MaybePartialRecord} */
8
+ export type ReadonlyMaybePartialRecord<K extends string | number, V> = string extends K ? {
9
+ +readonly [key in K]: V;
10
+ } : {
11
+ +readonly [key in K]+?: V;
12
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });