@peerbit/server 5.0.70 → 5.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/server",
3
- "version": "5.0.70",
3
+ "version": "5.1.0",
4
4
  "author": "dao.xyz",
5
5
  "repository": {
6
6
  "type": "git",
package/src/cli.ts CHANGED
@@ -1039,15 +1039,29 @@ export const cli = async (args?: string[]) => {
1039
1039
  variant: args.variant,
1040
1040
  };
1041
1041
  }
1042
+ const knownKeys = new Set([
1043
+ "program",
1044
+ "base64",
1045
+ "variant",
1046
+ "_",
1047
+ "$0",
1048
+ ]);
1049
+ const extraArgs = Object.fromEntries(
1050
+ Object.entries(args).filter(
1051
+ ([key]) => !knownKeys.has(key),
1052
+ ),
1053
+ );
1054
+ const mergedArgs = { ...startArg, ...extraArgs };
1055
+
1042
1056
  for (const api of apis) {
1043
1057
  const address =
1044
- await api.api.program.open(startArg);
1058
+ await api.api.program.open(mergedArgs);
1045
1059
  api.log("Started program with address: ");
1046
1060
  api.log(chalk.green(address.toString()));
1047
1061
  }
1048
1062
  },
1049
1063
  })
1050
- .strict()
1064
+ .strict(false) // because we have generic args
1051
1065
  .demandCommand();
1052
1066
  return yargs;
1053
1067
  })
package/src/client.ts CHANGED
@@ -158,11 +158,11 @@ export const createClient = async (
158
158
  return result.status === 200 ? true : false;
159
159
  },
160
160
 
161
- open: async (program: StartProgram): Promise<Address> => {
161
+ open: async (args: StartProgram): Promise<Address> => {
162
162
  const resp = throwIfNot200(
163
163
  await axiosInstance.put(
164
164
  endpoint + PROGRAM_PATH,
165
- JSON.stringify(program),
165
+ JSON.stringify(args),
166
166
  {
167
167
  validateStatus,
168
168
  },
package/src/server.ts CHANGED
@@ -408,6 +408,9 @@ export const startApiServer = async (
408
408
  case "PUT":
409
409
  try {
410
410
  const startArguments: StartProgram = JSON.parse(body);
411
+ const extraArgs = { ...startArguments };
412
+ delete extraArgs.variant;
413
+ delete extraArgs.base64;
411
414
 
412
415
  let program: Program;
413
416
  if ((startArguments as StartByVariant).variant) {
@@ -430,7 +433,12 @@ export const startApiServer = async (
430
433
  );
431
434
  }
432
435
  client
433
- .open(program) // TODO all users to pass args
436
+ .open(program, {
437
+ args:
438
+ Object.keys(extraArgs).length > 0
439
+ ? extraArgs
440
+ : undefined,
441
+ })
434
442
  .then(async (program) => {
435
443
  // TODO what if this is a reopen?
436
444
  await properties?.session?.programs.add(
package/src/types.ts CHANGED
@@ -4,7 +4,10 @@ export interface StartByVariant {
4
4
  export interface StartByBase64 {
5
5
  base64: string;
6
6
  }
7
- export type StartProgram = StartByVariant | StartByBase64;
7
+ export interface AnyArgs {
8
+ [key: string]: any; // Allow extra generic properties
9
+ }
10
+ export type StartProgram = (StartByVariant | StartByBase64) & AnyArgs;
8
11
 
9
12
  export interface InstallWithTGZ {
10
13
  type: "tgz";