@devvit/shared-types 0.11.0-next-2024-08-12-966265c0a.0 → 0.11.0-next-2024-08-12-80e9fc2a4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,83 @@
1
+ import type { Definition, SerializableServiceDefinition } from '@devvit/protos';
2
+ import type { Namespace } from './Namespace.js';
3
+ /** Actor in the platform, not in a user Bundle. */
4
+ export declare const PLUGIN_NAME: string;
5
+ /** Actor in the platform, not in a user Bundle. */
6
+ export declare const PLUGIN_OWNER: string;
7
+ export declare const LOCAL_HOSTNAME: string;
8
+ export declare const NODE_HOSTNAME = "node";
9
+ export declare const ECHO_CNAME = "echo";
10
+ export declare const INSPECTOR_CNAME = "inspector";
11
+ export declare const RUNTIME_CNAME = "runtime";
12
+ export declare const SUPERVISOR_CNAME = "supervisor";
13
+ export declare const SCHEDULER_CNAME = "scheduler";
14
+ export declare const REDDIT_API_CNAME = "redditapi";
15
+ export declare function resolveActorHostname(name: string, namespace: Readonly<Namespace>): string;
16
+ export declare function resolvePluginHostname(name: string, namespace: Readonly<Namespace>): string;
17
+ export declare function resolveSystemHostname(name: string, namespace: Readonly<Namespace>): string;
18
+ export declare function resolveActorDefinitionHostname(definition: Readonly<Definition | SerializableServiceDefinition>, namespace: Readonly<Namespace>): string;
19
+ export declare function resolvePluginDefinitionHostname(definition: Readonly<Definition | SerializableServiceDefinition>, namespace: Readonly<Namespace>): string;
20
+ export declare function resolveSystemDefinitionHostname(definition: Readonly<Definition | SerializableServiceDefinition>, namespace: Readonly<Namespace>): string;
21
+ /**
22
+ * Forms a hostname under namespace. Eg:
23
+ *
24
+ * 123, abc.local → 123.abc.local
25
+ * 123, local → 123.local
26
+ */
27
+ export declare function childHostname(name: string, namespace: Readonly<Namespace>): string;
28
+ /**
29
+ * Forms a hostname with the same parent as namespace. Eg:
30
+ *
31
+ * 123, abc.def.local → 123.def.local
32
+ * 123, def.local → 123.local
33
+ * 123, local → 123
34
+ */
35
+ export declare function siblingHostname(name: string, namespace: Readonly<Namespace>): string;
36
+ /**
37
+ * Returns the next level up of hostname. Eg:
38
+ *
39
+ * 123.abc.local → abc.local
40
+ * abc.local → local
41
+ * local → ''
42
+ */
43
+ export declare function parentHostname(hostname: string): string;
44
+ export declare function parentHostname(namespace: Namespace): string;
45
+ /**
46
+ * Returns true if left-hand-side is or descends from right-hand-side. Ex:
47
+ *
48
+ * | LHS | RHS | Output |
49
+ * | ------- | ----- | ------ |
50
+ * | local | local | true |
51
+ * | a.local | local | true |
52
+ * | a.node | local | false |
53
+ */
54
+ export declare function isDescendantHostname(lhs: string, rhs: string): boolean;
55
+ export declare namespace Hostname {
56
+ /**
57
+ * Returns the leaf subdomain of hostname. Ex:
58
+ *
59
+ * | Hostname | Output |
60
+ * | -------- | ------ |
61
+ * | local | local |
62
+ * | a.local | a |
63
+ * | a.node | a |
64
+ * | a.b.node | a |
65
+ */
66
+ function getChild(hostname: string): string;
67
+ /**
68
+ * Returns the leaf subdomain of hostname. Ex:
69
+ *
70
+ * | Hostname | Output |
71
+ * | -------- | ------ |
72
+ * | local | local |
73
+ * | a.local | local |
74
+ * | a.node | node |
75
+ * | a.b.node | local |
76
+ */
77
+ function getRoot(hostname: string): string;
78
+ function getPluginNamespace(namespace: Readonly<Namespace>): Namespace;
79
+ function getSystemNamespace(namespace: Readonly<Namespace>): Namespace;
80
+ function isPlugin(hostname: string, namespace: Readonly<Namespace>): boolean;
81
+ function isSystem(hostname: string, namespace: Readonly<Namespace>): boolean;
82
+ }
83
+ //# sourceMappingURL=HostnameUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostnameUtil.d.ts","sourceRoot":"","sources":["../src/HostnameUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,mDAAmD;AACnD,eAAO,MAAM,WAAW,EAAE,MAAkB,CAAC;AAE7C,m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;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,MAAM,CAIpF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;AACzD,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;AAQ7D;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAGtE;AAOD,yBAAiB,QAAQ,CAAC;IACxB;;;;;;;;;OASG;IACH,SAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;IAED;;;;;;;;;OASG;IACH,SAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhD;IAED,SAAgB,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAE5E;IAED,SAAgB,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAE5E;IAED,SAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,CAElF;IAED,SAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,CAElF;CACF"}
@@ -0,0 +1,127 @@
1
+ import { NonNull } from './NonNull.js';
2
+ /** Actor in the platform, not in a user Bundle. */
3
+ export const PLUGIN_NAME = 'default';
4
+ /** Actor in the platform, not in a user Bundle. */
5
+ export const PLUGIN_OWNER = 'devvit';
6
+ export const LOCAL_HOSTNAME = 'local';
7
+ export const NODE_HOSTNAME = 'node';
8
+ export const ECHO_CNAME = 'echo';
9
+ export const INSPECTOR_CNAME = 'inspector';
10
+ export const RUNTIME_CNAME = 'runtime';
11
+ export const SUPERVISOR_CNAME = 'supervisor';
12
+ export const SCHEDULER_CNAME = 'scheduler';
13
+ export const REDDIT_API_CNAME = 'redditapi';
14
+ export function resolveActorHostname(name, namespace) {
15
+ return childHostname(name, namespace);
16
+ }
17
+ export function resolvePluginHostname(name, namespace) {
18
+ return childHostname(name, Hostname.getPluginNamespace(namespace));
19
+ }
20
+ export function resolveSystemHostname(name, namespace) {
21
+ return childHostname(name, Hostname.getSystemNamespace(namespace));
22
+ }
23
+ export function resolveActorDefinitionHostname(definition, namespace) {
24
+ return resolveActorHostname(definition.name, namespace);
25
+ }
26
+ export function resolvePluginDefinitionHostname(definition, namespace) {
27
+ return resolvePluginHostname(definition.name, namespace);
28
+ }
29
+ export function resolveSystemDefinitionHostname(definition, namespace) {
30
+ return resolveSystemHostname(definition.name, namespace);
31
+ }
32
+ /**
33
+ * Forms a hostname under namespace. Eg:
34
+ *
35
+ * 123, abc.local → 123.abc.local
36
+ * 123, local → 123.local
37
+ */
38
+ export function childHostname(name, namespace) {
39
+ if (namespace.hostname == null)
40
+ throw Error('Unbound namespace.');
41
+ return `${name}.${namespace.hostname}`.toLocaleLowerCase();
42
+ }
43
+ /**
44
+ * Forms a hostname with the same parent as namespace. Eg:
45
+ *
46
+ * 123, abc.def.local → 123.def.local
47
+ * 123, def.local → 123.local
48
+ * 123, local → 123
49
+ */
50
+ export function siblingHostname(name, namespace) {
51
+ if (namespace.hostname == null)
52
+ throw Error('Unbound namespace.');
53
+ if (parentHostname(namespace) === name)
54
+ return name.toLocaleLowerCase();
55
+ return `${name.toLocaleLowerCase()}.${parentHostname(namespace)}`;
56
+ }
57
+ export function parentHostname(hostnameOrNamespace) {
58
+ const hostname = typeof hostnameOrNamespace === 'string' ? hostnameOrNamespace : hostnameOrNamespace.hostname;
59
+ if (hostname == null)
60
+ throw Error('Unbound namespace.');
61
+ return hostname.split('.').slice(1).join('.').toLocaleLowerCase();
62
+ }
63
+ /**
64
+ * Returns true if left-hand-side is or descends from right-hand-side. Ex:
65
+ *
66
+ * | LHS | RHS | Output |
67
+ * | ------- | ----- | ------ |
68
+ * | local | local | true |
69
+ * | a.local | local | true |
70
+ * | a.node | local | false |
71
+ */
72
+ export function isDescendantHostname(lhs, rhs) {
73
+ const suffix = `.${rhs}`;
74
+ return lhs === rhs || (lhs.length > suffix.length && lhs.endsWith(suffix));
75
+ }
76
+ // to-do: Move other methods under namespace,
77
+ // `import {Hostname} from 'Hostname.js'` wherever used, and use like:
78
+ // - `Hostname.getParent('about.reddit.com')`,
79
+ // - `Hostname.getChild('about.reddit.com')`,
80
+ // - `Hostname.addChild('about', 'reddit.com')`
81
+ export var Hostname;
82
+ (function (Hostname) {
83
+ /**
84
+ * Returns the leaf subdomain of hostname. Ex:
85
+ *
86
+ * | Hostname | Output |
87
+ * | -------- | ------ |
88
+ * | local | local |
89
+ * | a.local | a |
90
+ * | a.node | a |
91
+ * | a.b.node | a |
92
+ */
93
+ function getChild(hostname) {
94
+ return hostname.split('.')[0];
95
+ }
96
+ Hostname.getChild = getChild;
97
+ /**
98
+ * Returns the leaf subdomain of hostname. Ex:
99
+ *
100
+ * | Hostname | Output |
101
+ * | -------- | ------ |
102
+ * | local | local |
103
+ * | a.local | local |
104
+ * | a.node | node |
105
+ * | a.b.node | local |
106
+ */
107
+ function getRoot(hostname) {
108
+ return NonNull(hostname.split('.').at(-1));
109
+ }
110
+ Hostname.getRoot = getRoot;
111
+ function getPluginNamespace(namespace) {
112
+ return { hostname: childHostname('plugins', namespace) };
113
+ }
114
+ Hostname.getPluginNamespace = getPluginNamespace;
115
+ function getSystemNamespace(namespace) {
116
+ return { hostname: childHostname('system', namespace) };
117
+ }
118
+ Hostname.getSystemNamespace = getSystemNamespace;
119
+ function isPlugin(hostname, namespace) {
120
+ return isDescendantHostname(hostname, NonNull(getPluginNamespace(namespace).hostname));
121
+ }
122
+ Hostname.isPlugin = isPlugin;
123
+ function isSystem(hostname, namespace) {
124
+ return isDescendantHostname(hostname, NonNull(getSystemNamespace(namespace).hostname));
125
+ }
126
+ Hostname.isSystem = isSystem;
127
+ })(Hostname || (Hostname = {}));
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostnameUtil.test.d.ts","sourceRoot":"","sources":["../src/HostnameUtil.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/shared-types",
3
- "version": "0.11.0-next-2024-08-12-966265c0a.0",
3
+ "version": "0.11.0-next-2024-08-12-80e9fc2a4.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,14 +24,14 @@
24
24
  },
25
25
  "types": "./index.d.ts",
26
26
  "dependencies": {
27
- "@devvit/protos": "0.11.0-next-2024-08-12-966265c0a.0",
27
+ "@devvit/protos": "0.11.0-next-2024-08-12-80e9fc2a4.0",
28
28
  "jsonschema": "1.4.1",
29
29
  "uuid": "9.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@devvit/eslint-config": "0.11.0-next-2024-08-12-966265c0a.0",
33
- "@devvit/repo-tools": "0.11.0-next-2024-08-12-966265c0a.0",
34
- "@devvit/tsconfig": "0.11.0-next-2024-08-12-966265c0a.0",
32
+ "@devvit/eslint-config": "0.11.0-next-2024-08-12-80e9fc2a4.0",
33
+ "@devvit/repo-tools": "0.11.0-next-2024-08-12-80e9fc2a4.0",
34
+ "@devvit/tsconfig": "0.11.0-next-2024-08-12-80e9fc2a4.0",
35
35
  "@types/redis-mock": "0.17.1",
36
36
  "@types/uuid": "9.0.0",
37
37
  "eslint": "8.9.0",
@@ -45,5 +45,5 @@
45
45
  "directory": "dist"
46
46
  },
47
47
  "source": "./src/index.ts",
48
- "gitHead": "a6e2b727919ed858a2fc2a79fd7b65ace6ee3b95"
48
+ "gitHead": "23da84d172e0345dbc474de2199d9102a5890ee9"
49
49
  }