@replit/protocol 0.4.21 → 0.4.22

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 (55) hide show
  1. package/README.md +54 -0
  2. package/dist/api/client.d.ts +202 -0
  3. package/dist/api/client.d.ts.map +1 -0
  4. package/dist/api/client.js +394 -0
  5. package/dist/api/features/features.d.ts +112 -0
  6. package/dist/api/features/features.d.ts.map +1 -0
  7. package/dist/api/features/features.js +199 -0
  8. package/dist/api/lore/lore.d.ts +543 -0
  9. package/dist/api/lore/lore.d.ts.map +1 -0
  10. package/dist/api/lore/lore.js +982 -0
  11. package/dist/api/lore/service.client.d.ts +283 -0
  12. package/dist/api/lore/service.client.d.ts.map +1 -0
  13. package/dist/api/lore/service.client.js +172 -0
  14. package/dist/api/lore/service.d.ts +1100 -0
  15. package/dist/api/lore/service.d.ts.map +1 -0
  16. package/dist/api/lore/service.js +2279 -0
  17. package/dist/api/powerup.d.ts +147 -0
  18. package/dist/api/powerup.d.ts.map +1 -0
  19. package/dist/api/powerup.js +286 -0
  20. package/dist/api/repl/repl.d.ts +552 -0
  21. package/dist/api/repl/repl.d.ts.map +1 -0
  22. package/dist/api/repl/repl.js +787 -0
  23. package/dist/api/signing.d.ts +618 -0
  24. package/dist/api/signing.d.ts.map +1 -0
  25. package/dist/api/signing.js +785 -0
  26. package/dist/api/token/token.d.ts +335 -0
  27. package/dist/api/token/token.d.ts.map +1 -0
  28. package/dist/api/token/token.js +463 -0
  29. package/dist/api/types.d.ts +8629 -0
  30. package/dist/api/types.d.ts.map +1 -0
  31. package/dist/api/types.js +17225 -0
  32. package/dist/google/protobuf/empty.d.ts +31 -0
  33. package/dist/google/protobuf/empty.d.ts.map +1 -0
  34. package/dist/google/protobuf/empty.js +41 -0
  35. package/dist/google/protobuf/field_mask.d.ts +239 -0
  36. package/dist/google/protobuf/field_mask.d.ts.map +1 -0
  37. package/dist/google/protobuf/field_mask.js +83 -0
  38. package/dist/google/protobuf/struct.d.ts +186 -0
  39. package/dist/google/protobuf/struct.d.ts.map +1 -0
  40. package/dist/google/protobuf/struct.js +337 -0
  41. package/dist/google/protobuf/timestamp.d.ts +156 -0
  42. package/dist/google/protobuf/timestamp.d.ts.map +1 -0
  43. package/dist/google/protobuf/timestamp.js +132 -0
  44. package/dist/index.d.ts +13 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +16 -0
  47. package/dist/package.json +3 -0
  48. package/iotester/index.d.ts +6 -6
  49. package/iotester/index.js +25 -12
  50. package/main/index.d.ts +6 -6
  51. package/main/index.js +25 -12
  52. package/package.json +43 -4
  53. package/gen.sh +0 -51
  54. package/jsdoc.js +0 -171
  55. package/pnpm-workspace.yaml +0 -6
@@ -2449,9 +2449,6 @@ export namespace replit {
2449
2449
  /** NixPackageSearchRequest filterBuilt. */
2450
2450
  public filterBuilt?: (boolean|null);
2451
2451
 
2452
- /** NixPackageSearchRequest _filterBuilt. */
2453
- public _filterBuilt?: "filterBuilt";
2454
-
2455
2452
  /**
2456
2453
  * Creates a new NixPackageSearchRequest instance using the specified properties.
2457
2454
  * @param [properties] Properties to set
@@ -2743,9 +2740,6 @@ export namespace replit {
2743
2740
  /** NixPackageInfoResponse package. */
2744
2741
  public package?: (replit.goval.api.NixPackage|null);
2745
2742
 
2746
- /** NixPackageInfoResponse _package. */
2747
- public _package?: "package";
2748
-
2749
2743
  /**
2750
2744
  * Creates a new NixPackageInfoResponse instance using the specified properties.
2751
2745
  * @param [properties] Properties to set
@@ -33354,6 +33348,9 @@ export namespace replit {
33354
33348
 
33355
33349
  /** CreateReplRequest copyHelium */
33356
33350
  copyHelium?: (boolean|null);
33351
+
33352
+ /** CreateReplRequest copyGitsafe */
33353
+ copyGitsafe?: (boolean|null);
33357
33354
  }
33358
33355
 
33359
33356
  /** Represents a CreateReplRequest. */
@@ -33383,6 +33380,9 @@ export namespace replit {
33383
33380
  /** CreateReplRequest copyHelium. */
33384
33381
  public copyHelium: boolean;
33385
33382
 
33383
+ /** CreateReplRequest copyGitsafe. */
33384
+ public copyGitsafe: boolean;
33385
+
33386
33386
  /** CreateReplRequest location. */
33387
33387
  public location?: ("cluster"|"continent");
33388
33388
 
package/iotester/index.js CHANGED
@@ -9872,12 +9872,7 @@
9872
9872
  // OneOf field names bound to virtual getters and setters
9873
9873
  var $oneOfFields;
9874
9874
 
9875
- /**
9876
- * NixPackageSearchRequest _filterBuilt.
9877
- * @member {"filterBuilt"|undefined} _filterBuilt
9878
- * @memberof replit.goval.api.NixPackageSearchRequest
9879
- * @instance
9880
- */
9875
+ // Virtual OneOf for proto3 optional field
9881
9876
  Object.defineProperty(NixPackageSearchRequest.prototype, "_filterBuilt", {
9882
9877
  get: $util.oneOfGetter($oneOfFields = ["filterBuilt"]),
9883
9878
  set: $util.oneOfSetter($oneOfFields)
@@ -10538,12 +10533,7 @@
10538
10533
  // OneOf field names bound to virtual getters and setters
10539
10534
  var $oneOfFields;
10540
10535
 
10541
- /**
10542
- * NixPackageInfoResponse _package.
10543
- * @member {"package"|undefined} _package
10544
- * @memberof replit.goval.api.NixPackageInfoResponse
10545
- * @instance
10546
- */
10536
+ // Virtual OneOf for proto3 optional field
10547
10537
  Object.defineProperty(NixPackageInfoResponse.prototype, "_package", {
10548
10538
  get: $util.oneOfGetter($oneOfFields = ["package"]),
10549
10539
  set: $util.oneOfSetter($oneOfFields)
@@ -84932,6 +84922,7 @@
84932
84922
  * @property {replit.goval.api.lore.ReplLocation|replit.goval.api.lore.IReplLocation|null} [replLocation] CreateReplRequest replLocation
84933
84923
  * @property {replit.goval.api.lore.CreateReplRequest.SourceRepl|replit.goval.api.lore.CreateReplRequest.ISourceRepl|null} [sourceRepl] CreateReplRequest sourceRepl
84934
84924
  * @property {boolean|null} [copyHelium] CreateReplRequest copyHelium
84925
+ * @property {boolean|null} [copyGitsafe] CreateReplRequest copyGitsafe
84935
84926
  */
84936
84927
 
84937
84928
  /**
@@ -84996,6 +84987,14 @@
84996
84987
  */
84997
84988
  CreateReplRequest.prototype.copyHelium = false;
84998
84989
 
84990
+ /**
84991
+ * CreateReplRequest copyGitsafe.
84992
+ * @member {boolean} copyGitsafe
84993
+ * @memberof replit.goval.api.lore.CreateReplRequest
84994
+ * @instance
84995
+ */
84996
+ CreateReplRequest.prototype.copyGitsafe = false;
84997
+
84999
84998
  // OneOf field names bound to virtual getters and setters
85000
84999
  var $oneOfFields;
85001
85000
 
@@ -85046,6 +85045,8 @@
85046
85045
  $root.replit.goval.api.lore.ReplLocation.encode(message.replLocation, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim();
85047
85046
  if (message.copyHelium != null && Object.hasOwnProperty.call(message, "copyHelium"))
85048
85047
  writer.uint32(/* id 8, wireType 0 =*/64).bool(message.copyHelium);
85048
+ if (message.copyGitsafe != null && Object.hasOwnProperty.call(message, "copyGitsafe"))
85049
+ writer.uint32(/* id 9, wireType 0 =*/72).bool(message.copyGitsafe);
85049
85050
  return writer;
85050
85051
  };
85051
85052
 
@@ -85106,6 +85107,10 @@
85106
85107
  message.copyHelium = reader.bool();
85107
85108
  break;
85108
85109
  }
85110
+ case 9: {
85111
+ message.copyGitsafe = reader.bool();
85112
+ break;
85113
+ }
85109
85114
  default:
85110
85115
  reader.skipType(tag & 7);
85111
85116
  break;
@@ -85172,6 +85177,9 @@
85172
85177
  if (message.copyHelium != null && message.hasOwnProperty("copyHelium"))
85173
85178
  if (typeof message.copyHelium !== "boolean")
85174
85179
  return "copyHelium: boolean expected";
85180
+ if (message.copyGitsafe != null && message.hasOwnProperty("copyGitsafe"))
85181
+ if (typeof message.copyGitsafe !== "boolean")
85182
+ return "copyGitsafe: boolean expected";
85175
85183
  return null;
85176
85184
  };
85177
85185
 
@@ -85208,6 +85216,8 @@
85208
85216
  }
85209
85217
  if (object.copyHelium != null)
85210
85218
  message.copyHelium = Boolean(object.copyHelium);
85219
+ if (object.copyGitsafe != null)
85220
+ message.copyGitsafe = Boolean(object.copyGitsafe);
85211
85221
  return message;
85212
85222
  };
85213
85223
 
@@ -85229,6 +85239,7 @@
85229
85239
  object.sourceRepl = null;
85230
85240
  object.replLocation = null;
85231
85241
  object.copyHelium = false;
85242
+ object.copyGitsafe = false;
85232
85243
  }
85233
85244
  if (message.repl != null && message.hasOwnProperty("repl"))
85234
85245
  object.repl = $root.replit.goval.api.lore.CreateReplRequest.Repl.toObject(message.repl, options);
@@ -85248,6 +85259,8 @@
85248
85259
  object.replLocation = $root.replit.goval.api.lore.ReplLocation.toObject(message.replLocation, options);
85249
85260
  if (message.copyHelium != null && message.hasOwnProperty("copyHelium"))
85250
85261
  object.copyHelium = message.copyHelium;
85262
+ if (message.copyGitsafe != null && message.hasOwnProperty("copyGitsafe"))
85263
+ object.copyGitsafe = message.copyGitsafe;
85251
85264
  return object;
85252
85265
  };
85253
85266
 
package/main/index.d.ts CHANGED
@@ -2449,9 +2449,6 @@ export namespace replit {
2449
2449
  /** NixPackageSearchRequest filterBuilt. */
2450
2450
  public filterBuilt?: (boolean|null);
2451
2451
 
2452
- /** NixPackageSearchRequest _filterBuilt. */
2453
- public _filterBuilt?: "filterBuilt";
2454
-
2455
2452
  /**
2456
2453
  * Creates a new NixPackageSearchRequest instance using the specified properties.
2457
2454
  * @param [properties] Properties to set
@@ -2743,9 +2740,6 @@ export namespace replit {
2743
2740
  /** NixPackageInfoResponse package. */
2744
2741
  public package?: (replit.goval.api.NixPackage|null);
2745
2742
 
2746
- /** NixPackageInfoResponse _package. */
2747
- public _package?: "package";
2748
-
2749
2743
  /**
2750
2744
  * Creates a new NixPackageInfoResponse instance using the specified properties.
2751
2745
  * @param [properties] Properties to set
@@ -33354,6 +33348,9 @@ export namespace replit {
33354
33348
 
33355
33349
  /** CreateReplRequest copyHelium */
33356
33350
  copyHelium?: (boolean|null);
33351
+
33352
+ /** CreateReplRequest copyGitsafe */
33353
+ copyGitsafe?: (boolean|null);
33357
33354
  }
33358
33355
 
33359
33356
  /** Represents a CreateReplRequest. */
@@ -33383,6 +33380,9 @@ export namespace replit {
33383
33380
  /** CreateReplRequest copyHelium. */
33384
33381
  public copyHelium: boolean;
33385
33382
 
33383
+ /** CreateReplRequest copyGitsafe. */
33384
+ public copyGitsafe: boolean;
33385
+
33386
33386
  /** CreateReplRequest location. */
33387
33387
  public location?: ("cluster"|"continent");
33388
33388
 
package/main/index.js CHANGED
@@ -9872,12 +9872,7 @@
9872
9872
  // OneOf field names bound to virtual getters and setters
9873
9873
  var $oneOfFields;
9874
9874
 
9875
- /**
9876
- * NixPackageSearchRequest _filterBuilt.
9877
- * @member {"filterBuilt"|undefined} _filterBuilt
9878
- * @memberof replit.goval.api.NixPackageSearchRequest
9879
- * @instance
9880
- */
9875
+ // Virtual OneOf for proto3 optional field
9881
9876
  Object.defineProperty(NixPackageSearchRequest.prototype, "_filterBuilt", {
9882
9877
  get: $util.oneOfGetter($oneOfFields = ["filterBuilt"]),
9883
9878
  set: $util.oneOfSetter($oneOfFields)
@@ -10538,12 +10533,7 @@
10538
10533
  // OneOf field names bound to virtual getters and setters
10539
10534
  var $oneOfFields;
10540
10535
 
10541
- /**
10542
- * NixPackageInfoResponse _package.
10543
- * @member {"package"|undefined} _package
10544
- * @memberof replit.goval.api.NixPackageInfoResponse
10545
- * @instance
10546
- */
10536
+ // Virtual OneOf for proto3 optional field
10547
10537
  Object.defineProperty(NixPackageInfoResponse.prototype, "_package", {
10548
10538
  get: $util.oneOfGetter($oneOfFields = ["package"]),
10549
10539
  set: $util.oneOfSetter($oneOfFields)
@@ -84932,6 +84922,7 @@
84932
84922
  * @property {replit.goval.api.lore.ReplLocation|replit.goval.api.lore.IReplLocation|null} [replLocation] CreateReplRequest replLocation
84933
84923
  * @property {replit.goval.api.lore.CreateReplRequest.SourceRepl|replit.goval.api.lore.CreateReplRequest.ISourceRepl|null} [sourceRepl] CreateReplRequest sourceRepl
84934
84924
  * @property {boolean|null} [copyHelium] CreateReplRequest copyHelium
84925
+ * @property {boolean|null} [copyGitsafe] CreateReplRequest copyGitsafe
84935
84926
  */
84936
84927
 
84937
84928
  /**
@@ -84996,6 +84987,14 @@
84996
84987
  */
84997
84988
  CreateReplRequest.prototype.copyHelium = false;
84998
84989
 
84990
+ /**
84991
+ * CreateReplRequest copyGitsafe.
84992
+ * @member {boolean} copyGitsafe
84993
+ * @memberof replit.goval.api.lore.CreateReplRequest
84994
+ * @instance
84995
+ */
84996
+ CreateReplRequest.prototype.copyGitsafe = false;
84997
+
84999
84998
  // OneOf field names bound to virtual getters and setters
85000
84999
  var $oneOfFields;
85001
85000
 
@@ -85046,6 +85045,8 @@
85046
85045
  $root.replit.goval.api.lore.ReplLocation.encode(message.replLocation, writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim();
85047
85046
  if (message.copyHelium != null && Object.hasOwnProperty.call(message, "copyHelium"))
85048
85047
  writer.uint32(/* id 8, wireType 0 =*/64).bool(message.copyHelium);
85048
+ if (message.copyGitsafe != null && Object.hasOwnProperty.call(message, "copyGitsafe"))
85049
+ writer.uint32(/* id 9, wireType 0 =*/72).bool(message.copyGitsafe);
85049
85050
  return writer;
85050
85051
  };
85051
85052
 
@@ -85106,6 +85107,10 @@
85106
85107
  message.copyHelium = reader.bool();
85107
85108
  break;
85108
85109
  }
85110
+ case 9: {
85111
+ message.copyGitsafe = reader.bool();
85112
+ break;
85113
+ }
85109
85114
  default:
85110
85115
  reader.skipType(tag & 7);
85111
85116
  break;
@@ -85172,6 +85177,9 @@
85172
85177
  if (message.copyHelium != null && message.hasOwnProperty("copyHelium"))
85173
85178
  if (typeof message.copyHelium !== "boolean")
85174
85179
  return "copyHelium: boolean expected";
85180
+ if (message.copyGitsafe != null && message.hasOwnProperty("copyGitsafe"))
85181
+ if (typeof message.copyGitsafe !== "boolean")
85182
+ return "copyGitsafe: boolean expected";
85175
85183
  return null;
85176
85184
  };
85177
85185
 
@@ -85208,6 +85216,8 @@
85208
85216
  }
85209
85217
  if (object.copyHelium != null)
85210
85218
  message.copyHelium = Boolean(object.copyHelium);
85219
+ if (object.copyGitsafe != null)
85220
+ message.copyGitsafe = Boolean(object.copyGitsafe);
85211
85221
  return message;
85212
85222
  };
85213
85223
 
@@ -85229,6 +85239,7 @@
85229
85239
  object.sourceRepl = null;
85230
85240
  object.replLocation = null;
85231
85241
  object.copyHelium = false;
85242
+ object.copyGitsafe = false;
85232
85243
  }
85233
85244
  if (message.repl != null && message.hasOwnProperty("repl"))
85234
85245
  object.repl = $root.replit.goval.api.lore.CreateReplRequest.Repl.toObject(message.repl, options);
@@ -85248,6 +85259,8 @@
85248
85259
  object.replLocation = $root.replit.goval.api.lore.ReplLocation.toObject(message.replLocation, options);
85249
85260
  if (message.copyHelium != null && message.hasOwnProperty("copyHelium"))
85250
85261
  object.copyHelium = message.copyHelium;
85262
+ if (message.copyGitsafe != null && message.hasOwnProperty("copyGitsafe"))
85263
+ object.copyGitsafe = message.copyGitsafe;
85251
85264
  return object;
85252
85265
  };
85253
85266
 
package/package.json CHANGED
@@ -1,18 +1,57 @@
1
1
  {
2
2
  "name": "@replit/protocol",
3
- "version": "0.4.21",
3
+ "version": "0.4.22",
4
4
  "description": "JavaScript bindings for the Replit protocol",
5
5
  "main": "main/index.js",
6
+ "types": "main/index.d.ts",
6
7
  "author": "eng@replit.com",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./main/index.d.ts",
11
+ "default": "./main/index.js"
12
+ },
13
+ "./main": {
14
+ "types": "./main/index.d.ts",
15
+ "default": "./main/index.js"
16
+ },
17
+ "./main/*": "./main/*",
18
+ "./iotester": {
19
+ "types": "./iotester/index.d.ts",
20
+ "default": "./iotester/index.js"
21
+ },
22
+ "./iotester/*": "./iotester/*",
23
+ "./esm": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./esm/*": {
28
+ "types": "./dist/*.d.ts",
29
+ "default": "./dist/*.js"
30
+ }
31
+ },
32
+ "sideEffects": false,
33
+ "files": [
34
+ "main/",
35
+ "iotester/",
36
+ "dist/",
37
+ "README.md"
38
+ ],
7
39
  "dependencies": {
40
+ "@protobuf-ts/runtime": "^2.11.1",
41
+ "@protobuf-ts/runtime-rpc": "^2.11.1",
8
42
  "protobufjs": "^7.2.5"
9
43
  },
10
44
  "devDependencies": {
11
- "protobufjs-cli": "^1.1.2"
45
+ "@protobuf-ts/plugin": "^2.11.1",
46
+ "@protobuf-ts/protoc": "^2.11.1",
47
+ "protobufjs-cli": "^1.1.2",
48
+ "typescript": "^5.9.3"
12
49
  },
13
50
  "scripts": {
14
- "build": "pnpm run build:main && pnpm run build:iotester",
51
+ "build": "pnpm run build:legacy && pnpm run build:esm",
52
+ "build:legacy": "pnpm run build:main && pnpm run build:iotester",
53
+ "build:main": "TARGET='./main/index' ./gen.sh fix",
15
54
  "build:iotester": "TARGET='./iotester/index' ./gen.sh nofix ../../cmd/io-tester/lib/api/api.proto",
16
- "build:main": "TARGET='./main/index' ./gen.sh fix"
55
+ "build:esm": "./gen-pbts.sh"
17
56
  }
18
57
  }
package/gen.sh DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -e
4
-
5
- REPO_ROOT_DIR=$(git rev-parse --show-toplevel)
6
- export PATH="${PATH}:./node_modules/.bin"
7
- export TARGET="${TARGET:-./index}"
8
-
9
- MODE=$1
10
- shift 1
11
-
12
- mkdir -p "$(dirname "${TARGET}")"
13
-
14
- pbjs \
15
- --force-number \
16
- --force-message \
17
- -t static-module \
18
- -w default \
19
- -o "${TARGET}.js" \
20
- --root "${TARGET}" \
21
- --path "${REPO_ROOT_DIR}" \
22
- "$REPO_ROOT_DIR/api/types.proto" \
23
- "$REPO_ROOT_DIR/api/client.proto" \
24
- "$REPO_ROOT_DIR/api/signing.proto" \
25
- "$REPO_ROOT_DIR/api/token/token.proto" \
26
- "$REPO_ROOT_DIR/api/lore/lore.proto" \
27
- "$REPO_ROOT_DIR/api/lore/service.proto" \
28
- "$REPO_ROOT_DIR/api/features/features.proto" \
29
- "$REPO_ROOT_DIR/api/repl/repl.proto" \
30
- "$REPO_ROOT_DIR/api/powerup.proto" \
31
-
32
- if [ "$MODE" = "fix" ]; then
33
- # TODO: Remove this hack
34
- sed -i.bak 's@return $root;@$root.api = $root.replit.goval.api; return $root;@' "${TARGET}.js"
35
- rm -f "${TARGET}.js.bak"
36
- fi
37
-
38
- ./jsdoc.js <"${TARGET}.js" >"${TARGET}.tmp.js"
39
-
40
- mv "${TARGET}.tmp.js" "${TARGET}.js"
41
-
42
- pbts -o "${TARGET}.d.ts" "${TARGET}.js"
43
-
44
- if [ "$MODE" = "fix" ]; then
45
- # TODO: Remove this hack
46
- echo 'import api = replit.goval.api; export { api };' >> "${TARGET}.d.ts"
47
- fi
48
-
49
- sed -i.bak 's/constructor(/private constructor(/' "${TARGET}.d.ts"
50
-
51
- rm -f "${TARGET}.d.ts.bak"
package/jsdoc.js DELETED
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * @file A tool that fixes the pbjs-generated JSDoc annotations so that it can
4
- * produce sound TypeScript and Flow type declarations.
5
- * @flow
6
- */
7
- 'use strict';
8
-
9
- const fs = require('fs');
10
-
11
- // The regex that matches a JSDoc comment.
12
- const commentRegex = new RegExp('/\\*\\*([^*]|\\*[^/])*\\*/', 'smg');
13
-
14
- // The regex that matches an `@interface` JSDoc line.
15
- const interfaceRegex = new RegExp('@interface\\s+(\\S+)\\s*');
16
-
17
- // The regex that matches an `@implements` JSDoc line.
18
- const implementsRegex = new RegExp('.*@implements\\b.+\n');
19
-
20
- // The regex that matches a `@memberof` JSDoc line.
21
- const memberofRegex = new RegExp('@memberof\\s+(.*)\\s*');
22
-
23
- // The regex that matches a `@property` JSDoc line.
24
- const propertyRegex = new RegExp('@property\\s+\\{([^}]+)\\}', 'g');
25
-
26
- // The regex that matches a proto repeated field type.
27
- const arrayTypeRegex = new RegExp('^Array\\.<(.+)>$');
28
-
29
- // The regex that matches a proto map field type.
30
- const mapTypeRegex = new RegExp('^Object\\.<string,(.+)>$');
31
-
32
- /**
33
- * Fixes a property type in an interface declaration.
34
- *
35
- * This does one of the following transformations:
36
- *
37
- * - For primitive types (number, boolean, etc.), it leaves the type as-is.
38
- * - For repeated types, it recursively fixes the type of the elements of the
39
- * array.
40
- * - For map types, it recursively fixes the type of the values of the map.
41
- * - For message types, it allows both the concrete message (with all the
42
- * fields filled in) as well as the abstract interface (that allows for all
43
- * fields to be optional, in accordance with proto3 semantics).
44
- *
45
- * @param {string} typeName the name of the property.
46
- * @param {Set<string>} interfaces the declared interfaces in this file
47
- * @returns {string} the fixed property type.
48
- */
49
- function fixPropertyType(typeName, interfaces) {
50
- switch (typeName) {
51
- case 'number':
52
- case 'boolean':
53
- case 'string':
54
- case 'Uint8Array':
55
- case 'null':
56
- return typeName;
57
- }
58
-
59
- // proto repeated fields.
60
- let match = arrayTypeRegex.exec(typeName);
61
- if (match !== null) {
62
- return `Array.<${fixPropertyType(match[1], interfaces)}>`;
63
- }
64
-
65
- // proto map fields.
66
- match = mapTypeRegex.exec(typeName);
67
- if (match !== null) {
68
- return `Object.<string,${fixPropertyType(match[1], interfaces)}>`;
69
- }
70
-
71
- // This is now a dot-separated fully qualified type name.
72
- const tokens = typeName.split('.');
73
- tokens[tokens.length - 1] = 'I' + tokens[tokens.length - 1];
74
- const interfaceName = tokens.join('.');
75
- if (!interfaces.has(interfaceName)) {
76
- return typeName;
77
- }
78
- return `${typeName}|${tokens.join('.')}`;
79
- }
80
-
81
- /**
82
- * Fixes JSDoc declarations. For concrete message declarations, it removes
83
- * @implements annotations that break the soundness of the type system, and for
84
- * interface message declarations, it allows for all message types to be either
85
- * the concrete message type or the abstract interface one.
86
- *
87
- * @param {string} jsDoc the contents of a JSDoc
88
- * @param {Set<string>} interfaces the declared interfaces in this file
89
- * @returns {string} the fixed JSDoc.
90
- */
91
- function fixJsDoc(jsDoc, interfaces) {
92
- if (jsDoc.indexOf('@interface') !== -1) {
93
- // This is an interface declaration.
94
- jsDoc = jsDoc.replace(propertyRegex, (match, property) => {
95
- const options = property
96
- .split('|')
97
- .map((property) => fixPropertyType(property, interfaces))
98
- .join('|');
99
- return `@property {${options}}`;
100
- });
101
- } else {
102
- // This is a class declaration.
103
-
104
- // Remove any @implements annotations.
105
- jsDoc = jsDoc.replace(implementsRegex, '');
106
- }
107
- return jsDoc;
108
- }
109
-
110
- exports.main = function (args /*: string[] */) {
111
- const stdinBuffer = fs.readFileSync(0, 'utf-8');
112
-
113
- const interfaces /*: Set<string> */ = new Set();
114
- while (true) {
115
- const match = commentRegex.exec(stdinBuffer);
116
- if (match === null) {
117
- break;
118
- }
119
- const jsDoc = match[0];
120
- const memberofMatch = memberofRegex.exec(jsDoc);
121
- const interfaceMatch = interfaceRegex.exec(jsDoc);
122
- if (memberofMatch === null || interfaceMatch === null) {
123
- continue;
124
- }
125
- interfaces.add(`${memberofMatch[1]}.${interfaceMatch[1]}`);
126
- }
127
-
128
- const chunks = [];
129
- let lastIndex = 0;
130
- while (true) {
131
- const match = commentRegex.exec(stdinBuffer);
132
- if (match === null) {
133
- break;
134
- }
135
- chunks.push(stdinBuffer.slice(lastIndex, match.index));
136
- chunks.push(fixJsDoc(match[0], interfaces));
137
- lastIndex = match.index + match[0].length;
138
- }
139
- chunks.push(stdinBuffer.slice(lastIndex));
140
-
141
- // Finally, replace all `.create()` `new` invocations with a `.fromObject()`.
142
- // This is needed because protobufjs does not validate properties or create
143
- // instance objects when creating message types through `new`, but does so
144
- // through `.fromObject()`. Now, the downside of requiring people calling
145
- // `.fromObject()` is that it imposes no requirements on the type of its
146
- // argument (just that it's an object!), whereas `.create()` does require
147
- // that the argument is an interface.
148
- //
149
- // So this brings us the best of both worlds: `.create()` still has the right
150
- // types and creates fully reified objects, with the correct types all across
151
- // the board.
152
- const finalSource = chunks
153
- .join('')
154
- .replace(
155
- /(function create\(properties\)\s+{\n\s*)return new (\S+)(\(.*;\n\s*};)/gm,
156
- (match, prelude, className, postlude) =>
157
- `${prelude}return ${className}.fromObject${postlude}`
158
- )
159
- // For some reason Duration is serialized to JSON as an object rather than "{seconds}.{nanos}s".
160
- .replace(
161
- /(?<=Duration\.toObject = function toObject\(message, options\) {\n)(\s+)/gms,
162
- (_, indention) =>
163
- `if (options && options.json) {
164
- return \`\${message.seconds || 0}.\${message.nanos || 0}s\`.replace(/(0+(?=s$))/, '');
165
- }`.replace(/^/gm, indention) + `\n\n${indention}`
166
- );
167
-
168
- fs.writeSync(1, finalSource);
169
- };
170
-
171
- exports.main(process.argv);
@@ -1,6 +0,0 @@
1
- # This setting is intended to minimize the impact of supply-chain attacks.
2
- # In most cases, malicious releases are discovered within an hour, so
3
- # three days sounds safe.
4
- # If you need to immediately import something new (e.g. a security bugfix),
5
- # use the `minimumReleaseAgeExclude` to allow that package.
6
- minimumReleaseAge: 4320