@ibgib/core-gib 0.0.26 → 0.0.28

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 (87) hide show
  1. package/.vscode/core-gib-snippets.code-snippets +119 -13
  2. package/.vscode/settings.json +1 -0
  3. package/dist/witness/app/app-base-v1.d.mts +3 -3
  4. package/dist/witness/app/app-base-v1.d.mts.map +1 -1
  5. package/dist/witness/app/app-base-v1.mjs.map +1 -1
  6. package/dist/witness/app/app-types.d.mts +6 -6
  7. package/dist/witness/app/app-types.d.mts.map +1 -1
  8. package/dist/witness/app/app-types.mjs +1 -1
  9. package/dist/witness/app/app-types.mjs.map +1 -1
  10. package/dist/witness/keystone/keystone-base-v1.d.mts +183 -0
  11. package/dist/witness/keystone/keystone-base-v1.d.mts.map +1 -0
  12. package/dist/witness/keystone/keystone-base-v1.mjs +392 -0
  13. package/dist/witness/keystone/keystone-base-v1.mjs.map +1 -0
  14. package/dist/witness/keystone/keystone-constants.d.mts +2 -0
  15. package/dist/witness/keystone/keystone-constants.d.mts.map +1 -0
  16. package/dist/witness/keystone/keystone-constants.mjs +2 -0
  17. package/dist/witness/keystone/keystone-constants.mjs.map +1 -0
  18. package/dist/witness/keystone/keystone-helper.d.mts +9 -0
  19. package/dist/witness/keystone/keystone-helper.d.mts.map +1 -0
  20. package/dist/witness/keystone/keystone-helper.mjs +53 -0
  21. package/dist/witness/keystone/keystone-helper.mjs.map +1 -0
  22. package/dist/witness/keystone/keystone-types.d.mts +164 -0
  23. package/dist/witness/keystone/keystone-types.d.mts.map +1 -0
  24. package/dist/witness/keystone/keystone-types.mjs +46 -0
  25. package/dist/witness/keystone/keystone-types.mjs.map +1 -0
  26. package/dist/witness/keystone/keystone.d.mts +2 -0
  27. package/dist/witness/keystone/keystone.d.mts.map +1 -0
  28. package/dist/witness/keystone/keystone.mjs +2 -0
  29. package/dist/witness/keystone/keystone.mjs.map +1 -0
  30. package/dist/witness/keystone/keystone.respec.d.mts +11 -0
  31. package/dist/witness/keystone/keystone.respec.d.mts.map +1 -0
  32. package/dist/witness/keystone/keystone.respec.mjs +11 -0
  33. package/dist/witness/keystone/keystone.respec.mjs.map +1 -0
  34. package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts +2 -0
  35. package/dist/witness/keystone/math-keystone/math-keystone-constants.d.mts.map +1 -0
  36. package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs +2 -0
  37. package/dist/witness/keystone/math-keystone/math-keystone-constants.mjs.map +1 -0
  38. package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts +13 -0
  39. package/dist/witness/keystone/math-keystone/math-keystone-helper.d.mts.map +1 -0
  40. package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs +41 -0
  41. package/dist/witness/keystone/math-keystone/math-keystone-helper.mjs.map +1 -0
  42. package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts +80 -0
  43. package/dist/witness/keystone/math-keystone/math-keystone-types.d.mts.map +1 -0
  44. package/dist/witness/keystone/math-keystone/math-keystone-types.mjs +9 -0
  45. package/dist/witness/keystone/math-keystone/math-keystone-types.mjs.map +1 -0
  46. package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts +34 -0
  47. package/dist/witness/keystone/math-keystone/math-keystone-v1.d.mts.map +1 -0
  48. package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs +119 -0
  49. package/dist/witness/keystone/math-keystone/math-keystone-v1.mjs.map +1 -0
  50. package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts +20 -0
  51. package/dist/witness/keystone/math-keystone/math-keystone.respec.d.mts.map +1 -0
  52. package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs +76 -0
  53. package/dist/witness/keystone/math-keystone/math-keystone.respec.mjs.map +1 -0
  54. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts +2 -0
  55. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.d.mts.map +1 -0
  56. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs +2 -0
  57. package/dist/witness/keystone/zkp-keystone/zkp-keystone-constants.mjs.map +1 -0
  58. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts +2 -0
  59. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.d.mts.map +1 -0
  60. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs +2 -0
  61. package/dist/witness/keystone/zkp-keystone/zkp-keystone-helper.mjs.map +1 -0
  62. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts +2 -0
  63. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.d.mts.map +1 -0
  64. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs +2 -0
  65. package/dist/witness/keystone/zkp-keystone/zkp-keystone-types.mjs.map +1 -0
  66. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts +2 -0
  67. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.d.mts.map +1 -0
  68. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs +2 -0
  69. package/dist/witness/keystone/zkp-keystone/zkp-keystone-v1.mjs.map +1 -0
  70. package/package.json +1 -1
  71. package/src/witness/app/app-base-v1.mts +6 -6
  72. package/src/witness/app/app-types.mts +11 -8
  73. package/src/witness/keystone/keystone-base-v1.mts +450 -0
  74. package/src/witness/keystone/keystone-constants.mts +0 -0
  75. package/src/witness/keystone/keystone-helper.mts +56 -0
  76. package/src/witness/keystone/keystone-types.mts +200 -0
  77. package/src/witness/keystone/keystone.mts +0 -0
  78. package/src/witness/keystone/keystone.respec.mts +9 -0
  79. package/src/witness/keystone/math-keystone/math-keystone-constants.mts +0 -0
  80. package/src/witness/keystone/math-keystone/math-keystone-helper.mts +47 -0
  81. package/src/witness/keystone/math-keystone/math-keystone-types.mts +115 -0
  82. package/src/witness/keystone/math-keystone/math-keystone-v1.mts +139 -0
  83. package/src/witness/keystone/math-keystone/math-keystone.respec.mts +123 -0
  84. package/src/witness/keystone/zkp-keystone/zkp-keystone-constants.mts +0 -0
  85. package/src/witness/keystone/zkp-keystone/zkp-keystone-helper.mts +0 -0
  86. package/src/witness/keystone/zkp-keystone/zkp-keystone-types.mts +0 -0
  87. package/src/witness/keystone/zkp-keystone/zkp-keystone-v1.mts +0 -0
@@ -51,7 +51,7 @@ export abstract class AppBase_V1<
51
51
  TOptionsData, TOptionsRel8ns, TOptionsIbGib,
52
52
  TResultData, TResultRel8ns, TResultIbGib,
53
53
  TData, TRel8ns>
54
- implements AppIbGib_V1 {
54
+ implements AppIbGib_V1<TData, TRel8ns> {
55
55
 
56
56
  /**
57
57
  * Log context for convenience with logging. (Ignore if you don't want to use this.)
@@ -140,7 +140,7 @@ export abstract class AppBase_V1<
140
140
  const ibGib = arg as IbGib_V1;
141
141
  if (!isArg({ ibGib })) { throw new Error(`ibGib is not an arg (E: f0e36b13acbcdb1123ee72bdb9ee7723)`); }
142
142
  if (isCommand({ ibGib })) {
143
- return this.doCmdArg({ arg: arg as AppCmdIbGib<IbGib_V1, AppCmdData, AppCmdRel8ns> });
143
+ return this.doCmdArg({ arg: arg as AppCmdIbGib<IbGib_V1, any, any, AppCmdData<any, any>, AppCmdRel8ns> });
144
144
  } else if (isComment({ ibGib })) {
145
145
  return this.doComment({ ibGib: ibGib as CommentIbGib_V1 });
146
146
  } else if (isPic({ ibGib })) {
@@ -178,7 +178,7 @@ export abstract class AppBase_V1<
178
178
  protected doCmdArg({
179
179
  arg,
180
180
  }: {
181
- arg: AppCmdIbGib<IbGib_V1, AppCmdData, AppCmdRel8ns>,
181
+ arg: AppCmdIbGib<IbGib_V1, any, any, AppCmdData<any, any>, AppCmdRel8ns>,
182
182
  }): Promise<TResultIbGib> {
183
183
  const lc = `${this.lc}[${this.doCmdArg.name}]`;
184
184
  try {
@@ -368,10 +368,10 @@ export abstract class AppBase_V1<
368
368
  * wrapper convenience to avoid long generic calls.
369
369
  */
370
370
  async argy<
371
- TCmdOptionsData extends AppCmdData = AppCmdData,
371
+ TCmdOptionsData extends AppCmdData<any, any> = AppCmdData<any, any>,
372
372
  TCmdOptionsRel8ns extends AppCmdRel8ns = AppCmdRel8ns,
373
- TCmdOptionsIbGib extends AppCmdIbGib<IbGib_V1, TCmdOptionsData, TCmdOptionsRel8ns> =
374
- AppCmdIbGib<IbGib_V1, TCmdOptionsData, TCmdOptionsRel8ns>
373
+ TCmdOptionsIbGib extends AppCmdIbGib<IbGib_V1, any, any, TCmdOptionsData, TCmdOptionsRel8ns> =
374
+ AppCmdIbGib<IbGib_V1, any, any, TCmdOptionsData, TCmdOptionsRel8ns>
375
375
  >({
376
376
  argData,
377
377
  ibMetadata,
@@ -2,7 +2,6 @@ import { IbGibAddr, TransformResult } from '@ibgib/ts-gib';
2
2
  import { IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/index.mjs';
3
3
 
4
4
 
5
- // import { IonicSpaceData_V1 } from '../witnesses/spaces/ionic-space-v1';
6
5
  import {
7
6
  WitnessData_V1, WitnessRel8ns_V1,
8
7
  WitnessResultData, WitnessResultRel8ns, WitnessResultIbGib,
@@ -75,13 +74,15 @@ export interface AppRel8ns_V1 extends WitnessRel8ns_V1 {
75
74
 
76
75
  /**
77
76
  */
78
- export interface AppIbGib_V1 extends IbGib_V1<AppData_V1, AppRel8ns_V1> {
77
+ export interface AppIbGib_V1<TData extends AppData_V1 = any, TRel8ns extends AppRel8ns_V1 = any>
78
+ extends IbGib_V1<TData, TRel8ns> {
79
79
  }
80
80
 
81
+
81
82
  /**
82
- * Cmds for interacting with ibgib spaces.
83
+ * Cmds for interacting with ibgib app witnesses.
83
84
  *
84
- * Not all of these will be implemented for every space.
85
+ * Not all of these will be implemented for witness.
85
86
  *
86
87
  * ## todo
87
88
  *
@@ -89,7 +90,7 @@ export interface AppIbGib_V1 extends IbGib_V1<AppData_V1, AppRel8ns_V1> {
89
90
  * */
90
91
  export type AppCmd =
91
92
  'ib' | 'gib' | 'ibgib';
92
- /** Cmds for interacting with ibgib spaces. */
93
+ /** Cmds for interacting with ibgib app witnesses. */
93
94
  export const AppCmd = {
94
95
  /**
95
96
  * it's more like a grunt that is intepreted by context from the app.
@@ -136,8 +137,8 @@ export const AppCmdModifier = {
136
137
  }
137
138
 
138
139
  /** Information for interacting with spaces. */
139
- export interface AppCmdData
140
- extends WitnessCmdData<AppCmd, AppCmdModifier> {
140
+ export interface AppCmdData<TData extends AppCmd, TRel8ns extends AppCmdModifier>
141
+ extends WitnessCmdData<TData, TRel8ns> {
141
142
  }
142
143
 
143
144
  export interface AppCmdRel8ns extends WitnessCmdRel8ns {
@@ -150,7 +151,9 @@ export interface AppCmdRel8ns extends WitnessCmdRel8ns {
150
151
  */
151
152
  export interface AppCmdIbGib<
152
153
  TIbGib extends IbGib_V1 = IbGib_V1,
153
- TCmdData extends AppCmdData = AppCmdData,
154
+ TCmd extends AppCmd = AppCmd,
155
+ TCmdModifier extends AppCmdModifier = AppCmdModifier,
156
+ TCmdData extends AppCmdData<TCmd, TCmdModifier> = AppCmdData<TCmd, TCmdModifier>,
154
157
  TCmdRel8ns extends AppCmdRel8ns = AppCmdRel8ns,
155
158
  > extends WitnessCmdIbGib<TIbGib, AppCmd, AppCmdModifier, TCmdData, TCmdRel8ns> {
156
159
  }
@@ -0,0 +1,450 @@
1
+ import { IbGib_V1, IbGibRel8ns_V1, } from '@ibgib/ts-gib/dist/V1/index.mjs';
2
+
3
+ import { argy_, isArg, isCommand, resulty_ } from '../witness-helper.mjs';
4
+ import { MetaspaceService } from '../space/metaspace/metaspace-types.mjs';
5
+ import { WitnessWithContextBase_V1 } from '../witness-with-context/witness-with-context-base-v1.mjs';
6
+ import { ErrorIbGib_V1 } from '../../common/error/error-types.mjs';
7
+ import { errorIbGib } from '../../common/error/error-helper.mjs';
8
+
9
+ import {
10
+ KeystoneData_V1, KeystoneRel8ns_V1, KeystoneIbGib_V1,
11
+ KeystoneOptionsIbGib, KeystoneOptionsData, KeystoneOptionsRel8ns,
12
+ KeystoneResultIbGib, KeystoneResultData, KeystoneResultRel8ns,
13
+ KeystoneCmd, KeystoneCmdModifier,
14
+ // KeystoneCmd,
15
+ // KeystoneCmdData, KeystoneCmdRel8ns, KeystoneCmdIbGib,
16
+ // KeystoneResultData, KeystoneResultRel8ns, KeystoneResultIbGib,
17
+ } from './keystone-types.mjs';
18
+ import { validateCommonKeystoneData } from './keystone-helper.mjs';
19
+
20
+ import { PicIbGib_V1 } from '../../common/pic/pic-types.mjs';
21
+ import { CommentIbGib_V1 } from '../../common/comment/comment-types.mjs';
22
+
23
+
24
+ import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
25
+ const logalot = GLOBAL_LOG_A_LOT;
26
+
27
+ /**
28
+ * Keystone is the last major piece of the ibgib architecture. This is used to
29
+ * implement distributed identity that gets added on-chain alongside other data
30
+ * and metadata, instead of only relying solely upon asymmetric crypto for e.g.
31
+ * signatures.
32
+ *
33
+ * Override this class with specific concrete implementations of keystones,
34
+ * which atow I believe will differ mainly in their specific challenge
35
+ * implementations.
36
+ *
37
+ * ## notes
38
+ *
39
+ * ### composite keystones
40
+ *
41
+ * At first I was thinking I was going to make keystones composite (super
42
+ * keystones with rel8ns pointing to other keystones), but at least to start
43
+ * with, I will have a specific concrete implementation class that covers
44
+ * multiple keystone composition.
45
+ */
46
+ export abstract class KeystoneBase_V1<
47
+ TChallenges, TSolutions,
48
+ TOptionsData extends KeystoneOptionsData,
49
+ TOptionsRel8ns extends KeystoneOptionsRel8ns,
50
+ TOptionsIbGib extends KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns>,
51
+ TResultData extends KeystoneResultData,
52
+ TResultRel8ns extends KeystoneResultRel8ns,
53
+ TResultIbGib extends KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns> | ErrorIbGib_V1,
54
+ TData extends KeystoneData_V1<TChallenges, TSolutions>,
55
+ TRel8ns extends KeystoneRel8ns_V1,
56
+ >
57
+ extends WitnessWithContextBase_V1<
58
+ TOptionsData, TOptionsRel8ns, TOptionsIbGib,
59
+ TResultData, TResultRel8ns, TResultIbGib,
60
+ TData, TRel8ns>
61
+ implements KeystoneIbGib_V1<TData, TRel8ns> {
62
+
63
+ /**
64
+ * Log context for convenience with logging. (Ignore if you don't want to use this.)
65
+ */
66
+ protected lc: string = `[${KeystoneBase_V1.name}]`;
67
+
68
+ /**
69
+ * Reference to the local ibgibs service, which is one way at getting at the
70
+ * local user space.
71
+ */
72
+ ibgibsSvc: MetaspaceService | undefined;
73
+
74
+ constructor(initialData?: TData, initialRel8ns?: TRel8ns) {
75
+ super(initialData, initialRel8ns);
76
+ }
77
+
78
+ /**
79
+ * At this point in time, the arg has already been intrinsically validated,
80
+ * as well as the internal state of this keystone.
81
+ */
82
+ protected async witnessImpl(arg: TOptionsIbGib): Promise<TResultIbGib | undefined> {
83
+ const lc = `${this.lc}[${this.witnessImpl.name}]`;
84
+ try {
85
+ if (logalot) { console.log(`${lc} starting...`); }
86
+
87
+ await this.loadNewerSelfIfAvailable();
88
+
89
+ let result: TResultIbGib | undefined = undefined;
90
+
91
+ if (isArg({ ibGib: (arg as IbGib_V1) })) {
92
+ result = await this.routeAndDoArg({ arg });
93
+ } else {
94
+ result = await this.doNonArg({ ibGib: arg });
95
+ }
96
+
97
+ // if we didn't get a result, try the default.
98
+ if (!result) {
99
+ console.warn(`${lc} result still falsy. doing default handler. (W: 924d1fc93ad5464e81f71f2783d778a8)`);
100
+ result = await this.doDefault({ ibGib: arg });
101
+ }
102
+
103
+ if (!result) { console.warn(`${lc} result falsy...Could not produce result? Was doDefault implemented in concrete class? (W: 78861cb3c37546fa8f0b2bee4c50f832)`); }
104
+
105
+ return result;
106
+ } catch (error) {
107
+ console.error(`${lc} ${error.message}`);
108
+ throw error;
109
+ } finally {
110
+ if (logalot) { console.log(`${lc} complete.`); }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Base routing executes different if incoming is a cmd options arg, i.e.,
116
+ * if the `data.cmd` is truthy (atow). {@link isArg} is expected to be true
117
+ * at this point. If not, logs an error, **but does not throw**, and returns
118
+ * undefined.
119
+ *
120
+ * Default routing checks arg for command, or if not, checks if comment/pic.
121
+ * If neither of those, then returns undefined atow.
122
+ *
123
+ * Override this function to create more advanced custom routing.
124
+ *
125
+ * ## notes
126
+ *
127
+ * In general, an app ibgib acts more like a normal application in that it
128
+ * accepts commands and not requests. Robbots are more geared to requests,
129
+ * handled semantically.
130
+ *
131
+ * @see {@link isArg}
132
+ * @see {@link doCmdArg}
133
+ * @see {@link doDefault}.
134
+ */
135
+ protected async routeAndDoArg({
136
+ arg,
137
+ }: {
138
+ arg: TOptionsIbGib,
139
+ }): Promise<TResultIbGib | undefined> {
140
+ const lc = `${this.lc}[${this.routeAndDoArg.name}]`;
141
+ try {
142
+ if (logalot) { console.log(`${lc} starting...`); }
143
+ const ibGib = arg as IbGib_V1;
144
+ if (!isArg({ ibGib })) { throw new Error(`ibGib is not an arg (E: 7e5ed6e3be45480e992c75a1c21f1b4e)`); }
145
+ if (isCommand({ ibGib })) {
146
+ return this.doCmdArg({ arg });
147
+ } else {
148
+ return undefined;
149
+ }
150
+ } catch (error) {
151
+ console.error(`${lc} ${error.message}`);
152
+ if (this.data?.catchAllErrors) {
153
+ return (await errorIbGib({ rawMsg: error.message })) as TResultIbGib;
154
+ } else {
155
+ throw error;
156
+ }
157
+ } finally {
158
+ if (logalot) { console.log(`${lc} complete.`); }
159
+ }
160
+ }
161
+
162
+ // #region do cmd args
163
+
164
+ /**
165
+ * By default, this routes to {@link doCmdIb}, {@link doCmdGib} & {@link
166
+ * doCmdIbgib}. This is largely to limit scope of responsibility of app to
167
+ * basic functions. But this is not a concrete rule written in stone.
168
+ *
169
+ * You can always override this and route to other commands before calling
170
+ * this with `super.doCmdArg` as a fallback (if you still want to use this
171
+ * function.)
172
+ *
173
+ * Note that this @throws an error if the data.cmd is not recognized. In this
174
+ * implementation, this occurs if it isn't an ib/gib/ibgib _command_.
175
+ *
176
+ * ## commands
177
+ *
178
+ * ### confirm
179
+ *
180
+ * confirm possession of the keystone via the keystone's challenges as set
181
+ * out in the keystone's metadata.
182
+ *
183
+ * ### confirm final
184
+ *
185
+ * final confirmation of a secret of the stone. "kills" the stone once used.
186
+ * The point is to verify if a participant has the full secret of the stone,
187
+ * and not just mimicked part of the stone's ownership.
188
+ *
189
+ * ### revoke
190
+ *
191
+ * revoke due to being broken.
192
+ * maybe is a flavor of the confirm final?
193
+ */
194
+ protected doCmdArg({
195
+ arg,
196
+ }: {
197
+ arg: TOptionsIbGib,
198
+ }): Promise<TResultIbGib> {
199
+ const lc = `${this.lc}[${this.doCmdArg.name}]`;
200
+ try {
201
+ if (logalot) { console.log(`${lc} starting...`); }
202
+ if (!arg.data?.cmd) { throw new Error(`invalid cmd arg. arg.data.cmd required. (E: 470aabf26ca6406b84dbae3b9b39639d)`); }
203
+ if (arg.data.cmd === KeystoneCmd.ib) {
204
+ return this.doCmdIb({ arg: arg });
205
+ } else if (arg.data.cmd === KeystoneCmd.gib) {
206
+ return this.doCmdGib({ arg: arg });
207
+ } else if (arg.data.cmd === KeystoneCmd.ibgib) {
208
+ return this.doCmdIbgib({ arg: arg });
209
+ } else {
210
+ throw new Error(`unknown arg.data.cmd: ${arg.data.cmd} (E: 0eb81ae8c3834f47865af0ac7b7a9fd6)`);
211
+ }
212
+ } catch (error) {
213
+ console.error(`${lc} ${error.message}`);
214
+ throw error;
215
+ } finally {
216
+ if (logalot) { console.log(`${lc} complete.`); }
217
+ }
218
+ }
219
+ protected doCmdIb({
220
+ arg,
221
+ }: {
222
+ arg: TOptionsIbGib,
223
+ }): Promise<TResultIbGib> {
224
+ return this.extend({ arg });
225
+ }
226
+ /**
227
+ * this is the primary command handler when extending a keystone, i.e. when
228
+ * signing some payload.
229
+ */
230
+ protected abstract extend({ arg }: { arg: TOptionsIbGib }): Promise<TResultIbGib>;
231
+
232
+ protected doCmdGib({
233
+ arg,
234
+ }: {
235
+ arg: TOptionsIbGib,
236
+ }): Promise<TResultIbGib> {
237
+ const lc = `${this.lc}[${this.doCmdGib.name}]`;
238
+ try {
239
+ if (logalot) { console.log(`${lc} starting...`); }
240
+ throw new Error(`not implemented in base class (E: bb16814f46984a9dafac5b85d8ec1f74)`);
241
+ } catch (error) {
242
+ console.error(`${lc} ${error.message}`);
243
+ throw error;
244
+ } finally {
245
+ if (logalot) { console.log(`${lc} complete.`); }
246
+ }
247
+ }
248
+ protected doCmdIbgib({
249
+ arg,
250
+ }: {
251
+ arg: TOptionsIbGib,
252
+ }): Promise<TResultIbGib> {
253
+ const lc = `${this.lc}[${this.doCmdIbgib.name}]`;
254
+ try {
255
+ if (logalot) { console.log(`${lc} starting...`); }
256
+ throw new Error(`not implemented in base class (E: 6f3ed691d16a43f49145b2ed46fb28ba)`);
257
+ } catch (error) {
258
+ console.error(`${lc} ${error.message}`);
259
+ throw error;
260
+ } finally {
261
+ if (logalot) { console.log(`${lc} complete.`); }
262
+ }
263
+ }
264
+
265
+ // #endregion do cmd args
266
+
267
+ // #region other stubbed do functions (doPic, doComment, doDefault)
268
+
269
+ /**
270
+ * Stubbed in base class for convenience. Doesn't have to be implemented.
271
+ *
272
+ * in the future, this may be able to be used for physical object
273
+ * verification via picture.
274
+ */
275
+ protected doPic({
276
+ ibGib,
277
+ }: {
278
+ ibGib: PicIbGib_V1,
279
+ }): Promise<TResultIbGib | undefined> {
280
+ const lc = `${this.lc}[${this.doPic.name}]`;
281
+ try {
282
+ if (logalot) { console.log(`${lc} starting...`); }
283
+ throw new Error(`not implemented in base class (E: ce5c9b30622f4b3bab198dde04de75e7)`);
284
+ } catch (error) {
285
+ console.error(`${lc} ${error.message}`);
286
+ throw error;
287
+ } finally {
288
+ if (logalot) { console.log(`${lc} complete.`); }
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Stubbed in base class for convenience. Doesn't have to be implemented.
294
+ *
295
+ * in the future, this may be able to handle natural language and route
296
+ * accordingly.
297
+ */
298
+ protected doComment({
299
+ ibGib,
300
+ }: {
301
+ ibGib: CommentIbGib_V1,
302
+ }): Promise<TResultIbGib | undefined> {
303
+ const lc = `${this.lc}[${this.doComment.name}]`;
304
+ try {
305
+ if (logalot) { console.log(`${lc} starting...`); }
306
+
307
+ throw new Error(`not implemented in base class (E: c90f5bddaa58446fb4de638816974b6c)`);
308
+ } catch (error) {
309
+ console.error(`${lc} ${error.message}`);
310
+ throw error;
311
+ } finally {
312
+ if (logalot) { console.log(`${lc} complete.`); }
313
+ }
314
+ }
315
+
316
+ protected doNonArg({
317
+ ibGib,
318
+ }: {
319
+ ibGib: TOptionsIbGib,
320
+ }): Promise<TResultIbGib | undefined> {
321
+ const lc = `${this.lc}[${this.doNonArg.name}]`;
322
+ try {
323
+ if (logalot) { console.log(`${lc} starting...`); }
324
+ return this.doDefault({ ibGib });
325
+ } catch (error) {
326
+ console.error(`${lc} ${error.message}`);
327
+ throw error;
328
+ } finally {
329
+ if (logalot) { console.log(`${lc} complete.`); }
330
+ }
331
+ }
332
+ /**
333
+ * Stubbed in base class for convenience. Doesn't have to be implemented.
334
+ */
335
+ protected doDefault({
336
+ ibGib,
337
+ }: {
338
+ ibGib: TOptionsIbGib,
339
+ }): Promise<TResultIbGib | undefined> {
340
+ const lc = `${this.lc}[${this.doDefault.name}]`;
341
+ try {
342
+ if (logalot) { console.log(`${lc} starting...`); }
343
+ throw new Error(`not implemented in base class (E: bee031bb4c974a71bae82df7cff2b4e1)`);
344
+ // return this.doDefaultImpl({ibGib});
345
+ } catch (error) {
346
+ console.error(`${lc} ${error.message}`);
347
+ throw error;
348
+ } finally {
349
+ if (logalot) { console.log(`${lc} complete.`); }
350
+ }
351
+ }
352
+
353
+ // #endregion other stubbed do functions (doPic, doComment, doDefault)
354
+
355
+ /**
356
+ * validates against common app qualities.
357
+ *
358
+ * Override this with a call to `super.validateThis` for custom validation
359
+ * for descending app classes.
360
+ *
361
+ * @returns validation errors common to all apps, if any errors exist.
362
+ */
363
+ protected async validateThis(): Promise<string[]> {
364
+ const lc = `${this.lc}[${this.validateThis.name}]`;
365
+ try {
366
+ if (logalot) { console.log(`${lc} starting...`); }
367
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: bd4b0fc836774eb288b8b07ec79cb4af)`); }
368
+ const errors = [
369
+ // ...await super.validateThis(),
370
+ ...validateCommonKeystoneData({ appData: this.data }),
371
+ ];
372
+ return errors;
373
+ } catch (error) {
374
+ console.error(`${lc} ${error.message}`);
375
+ throw error;
376
+ } finally {
377
+ if (logalot) { console.log(`${lc} complete.`); }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * builds an arg ibGib.
383
+ *
384
+ * wrapper convenience to avoid long generic calls.
385
+ */
386
+ async argy<
387
+ TOptionsData extends KeystoneOptionsData = KeystoneOptionsData,
388
+ TOptionsRel8ns extends KeystoneOptionsRel8ns = KeystoneOptionsRel8ns,
389
+ TOptionsIbGib extends KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns> =
390
+ KeystoneOptionsIbGib<IbGib_V1, TOptionsData, TOptionsRel8ns>
391
+ >({
392
+ argData,
393
+ ibMetadata,
394
+ noTimestamp,
395
+ ibGibs,
396
+ }: {
397
+ argData: TOptionsData,
398
+ ibMetadata?: string,
399
+ noTimestamp?: boolean,
400
+ ibGibs?: IbGib_V1[],
401
+ }): Promise<TOptionsIbGib> {
402
+ const arg = await argy_<TOptionsData, TOptionsRel8ns, TOptionsIbGib>({
403
+ argData,
404
+ ibMetadata,
405
+ noTimestamp
406
+ });
407
+
408
+ if (ibGibs) { arg.ibGibs = ibGibs; }
409
+
410
+ return arg;
411
+ }
412
+
413
+ /**
414
+ * builds a result ibGib, if indeed a result ibgib is required.
415
+ *
416
+ * This is only useful in apps that have more structured inputs/outputs.
417
+ * For those that simply accept any ibgib incoming and return a
418
+ * primitive like ib^gib or whatever, then this is unnecessary.
419
+ *
420
+ * wrapper convenience to avoid long generic calls.
421
+ */
422
+ async resulty<
423
+ TResultData extends KeystoneResultData = KeystoneResultData,
424
+ TResultRel8ns extends KeystoneResultRel8ns = KeystoneResultRel8ns,
425
+ TResultIbGib extends KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns> =
426
+ KeystoneResultIbGib<IbGib_V1, TResultData, TResultRel8ns>
427
+ >({
428
+ resultData,
429
+ ibGibs,
430
+ }: {
431
+ resultData: TResultData,
432
+ ibGibs?: IbGib_V1[],
433
+ }): Promise<TResultIbGib> {
434
+ const result = await resulty_<TResultData, TResultIbGib>({
435
+ // ibMetadata: getKeystoneResultMetadata({space: this}),
436
+ resultData,
437
+ });
438
+ if (ibGibs) { result.ibGibs = ibGibs; }
439
+ return result;
440
+ }
441
+
442
+ }
443
+
444
+ /**
445
+ * useful for when passing around instances of keystones where implementation
446
+ * details are not important.
447
+ */
448
+ export interface IbGibKeystoneAny
449
+ extends KeystoneBase_V1<any, any, any, any, any, any, any, any, any, any> {
450
+ }
File without changes
@@ -0,0 +1,56 @@
1
+ import { GLOBAL_LOG_A_LOT } from "../../core-constants.mjs";
2
+ import { KeystoneData_V1 } from "./keystone-types.mjs";
3
+
4
+ const logalot = GLOBAL_LOG_A_LOT || false;
5
+
6
+ /**
7
+ * validation of data common to all keystones (i.e. at the base class level).
8
+ * @returns error strings array of any validation errors. empty if none
9
+ */
10
+ export function validateCommonKeystoneData({
11
+ appData,
12
+ }: {
13
+ appData: KeystoneData_V1<any, any> | undefined,
14
+ }): string[] {
15
+ const lc = `[${validateCommonKeystoneData.name}]`;
16
+ try {
17
+ if (logalot) { console.log(`${lc} starting...`); }
18
+ if (!appData) { throw new Error(`appData required (E: e22bd1940d1d436fbbed8126c11aa529)`); }
19
+ const errors: string[] = [];
20
+
21
+ console.warn(`${lc} not impl yet`)
22
+ // const {
23
+ // name, uuid, classname,
24
+ // } =
25
+ // appData;
26
+
27
+ // if (name) {
28
+ // if (!name.match(APP_NAME_REGEXP)) {
29
+ // errors.push(`name must match regexp: ${APP_NAME_REGEXP}`);
30
+ // }
31
+ // } else {
32
+ // errors.push(`name required.`);
33
+ // }
34
+
35
+ // if (uuid) {
36
+ // if (!uuid.match(UUID_REGEXP)) {
37
+ // errors.push(`uuid must match regexp: ${UUID_REGEXP}`);
38
+ // }
39
+ // } else {
40
+ // errors.push(`uuid required.`);
41
+ // }
42
+
43
+ // if (classname) {
44
+ // if (!classname.match(APP_NAME_REGEXP)) {
45
+ // errors.push(`classname must match regexp: ${APP_NAME_REGEXP}`);
46
+ // }
47
+ // }
48
+
49
+ return errors;
50
+ } catch (error) {
51
+ console.error(`${lc} ${error.message}`);
52
+ throw error;
53
+ } finally {
54
+ if (logalot) { console.log(`${lc} complete.`); }
55
+ }
56
+ }