@devvit/shared-types 0.10.25-next-2024-08-15-1214a0630.0 → 0.10.25-next-2024-08-19-f27845e8c.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Assets.d.ts +1 -0
- package/Assets.d.ts.map +1 -1
- package/Assets.js +1 -0
- package/Config.d.ts +1 -0
- package/Config.d.ts.map +1 -1
- package/ConfigImpl.d.ts +20 -0
- package/ConfigImpl.d.ts.map +1 -0
- package/ConfigImpl.js +80 -0
- package/HostnameUtil.d.ts +83 -0
- package/HostnameUtil.d.ts.map +1 -0
- package/HostnameUtil.js +127 -0
- package/HostnameUtil.test.d.ts.map +1 -0
- package/package.json +6 -6
package/Assets.d.ts
CHANGED
@@ -13,6 +13,7 @@ export type AssetMap = {
|
|
13
13
|
[path: string]: string;
|
14
14
|
};
|
15
15
|
export declare const ASSET_DIRNAME = "assets";
|
16
|
+
export declare const WEBVIEW_ASSET_DIRNAME = "webroot";
|
16
17
|
export declare const ALLOWED_ASSET_EXTENSIONS: string[];
|
17
18
|
export declare const KILOBYTE = 1024;
|
18
19
|
export declare const MEGABYTE: number;
|
package/Assets.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Assets.d.ts","sourceRoot":"","sources":["../src/Assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAElD,eAAO,MAAM,aAAa,WAAW,CAAC;
|
1
|
+
{"version":3,"file":"Assets.d.ts","sourceRoot":"","sources":["../src/Assets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAElD,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAK/C,eAAO,MAAM,wBAAwB,UAA6C,CAAC;AAEnF,eAAO,MAAM,QAAQ,OAAO,CAAC;AAC7B,eAAO,MAAM,QAAQ,QAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,QAAsB,CAAC;AAC5C,eAAO,MAAM,2BAA2B,QAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,QAAgB,CAAC;AAChD,eAAO,MAAM,sBAAsB,QAAgB,CAAC;AAEpD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYrD"}
|
package/Assets.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export const ASSET_DIRNAME = 'assets';
|
2
|
+
export const WEBVIEW_ASSET_DIRNAME = 'webroot';
|
2
3
|
// List of allowed asset extensions. Note that this should not be used as definitive proof that
|
3
4
|
// an asset is valid, as it is possible to spoof the extension of a file. This is just a quick
|
4
5
|
// check to make sure the file is probably an image.
|
package/Config.d.ts
CHANGED
@@ -13,6 +13,7 @@ import type { Namespace } from './Namespace.js';
|
|
13
13
|
export type Config = {
|
14
14
|
readonly assets: Readonly<AssetMap>;
|
15
15
|
readonly providedDefinitions: Readonly<Definition>[];
|
16
|
+
readonly webviewAssets?: Readonly<AssetMap> | undefined;
|
16
17
|
export(namespace: Readonly<Namespace>): DependencySpec;
|
17
18
|
provides(definition: Readonly<Definition>): void;
|
18
19
|
use<T>(definition: Readonly<Definition>, options?: Readonly<DeepPartial<PackageQuery>>): T;
|
package/Config.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB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,SAAS,CAAC,GAAG,cAAc,CAAC;IAEvD,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IAEjD,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC;IAE3F;;;;OAIG;IACH,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;CACjD,CAAC"}
|
package/ConfigImpl.d.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { ActorSpec, Definition, DependencySpec, PackageQuery } from '@devvit/protos';
|
2
|
+
import type { AssetMap } from './Assets.js';
|
3
|
+
import type { DeepPartial } from './BuiltinTypes.js';
|
4
|
+
import type { Config } from './Config.js';
|
5
|
+
import type { Namespace } from './Namespace.js';
|
6
|
+
export type ClientFactory = {
|
7
|
+
Build<T>(desc: Definition, spec: PackageQuery): T;
|
8
|
+
};
|
9
|
+
export declare class ConfigImpl implements Config {
|
10
|
+
#private;
|
11
|
+
get assets(): Readonly<AssetMap>;
|
12
|
+
get webviewAssets(): Readonly<AssetMap>;
|
13
|
+
get providedDefinitions(): Readonly<Definition>[];
|
14
|
+
constructor(factory: ClientFactory, actorSpec: ActorSpec, assets: AssetMap, webviewAssets: AssetMap);
|
15
|
+
export(namespace: Readonly<Namespace>): DependencySpec;
|
16
|
+
provides(definition: Readonly<Definition>): void;
|
17
|
+
use<T>(definition: Readonly<Definition>, options?: Readonly<DeepPartial<PackageQuery>>): T;
|
18
|
+
uses(definition: Readonly<Definition>): boolean;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=ConfigImpl.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ConfigImpl.d.ts","sourceRoot":"","sources":["../src/ConfigImpl.ts"],"names":[],"mappings":"AAAA,OAAO,E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) throw new TypeError("Private accessor was defined without a getter");
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
5
|
+
};
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
11
|
+
};
|
12
|
+
var _ConfigImpl_instances, _ConfigImpl_factory, _ConfigImpl_name, _ConfigImpl_owner, _ConfigImpl_provides, _ConfigImpl_useQueries, _ConfigImpl_version, _ConfigImpl_assets, _ConfigImpl_webviewAssets, _ConfigImpl_newActorSpec;
|
13
|
+
import { ActorSpec, Definition, DependencySpec, PackageQuery, PackageSpec } from '@devvit/protos';
|
14
|
+
import { NonNull } from './NonNull.js';
|
15
|
+
import { PLUGIN_NAME, resolveActorHostname } from './HostnameUtil.js';
|
16
|
+
export class ConfigImpl {
|
17
|
+
get assets() {
|
18
|
+
return __classPrivateFieldGet(this, _ConfigImpl_assets, "f");
|
19
|
+
}
|
20
|
+
get webviewAssets() {
|
21
|
+
return __classPrivateFieldGet(this, _ConfigImpl_webviewAssets, "f");
|
22
|
+
}
|
23
|
+
get providedDefinitions() {
|
24
|
+
return __classPrivateFieldGet(this, _ConfigImpl_provides, "f");
|
25
|
+
}
|
26
|
+
constructor(factory, actorSpec, assets, webviewAssets) {
|
27
|
+
_ConfigImpl_instances.add(this);
|
28
|
+
_ConfigImpl_factory.set(this, void 0);
|
29
|
+
_ConfigImpl_name.set(this, void 0);
|
30
|
+
_ConfigImpl_owner.set(this, void 0);
|
31
|
+
_ConfigImpl_provides.set(this, []);
|
32
|
+
_ConfigImpl_useQueries.set(this, []);
|
33
|
+
_ConfigImpl_version.set(this, void 0);
|
34
|
+
_ConfigImpl_assets.set(this, void 0);
|
35
|
+
_ConfigImpl_webviewAssets.set(this, void 0);
|
36
|
+
__classPrivateFieldSet(this, _ConfigImpl_factory, factory, "f");
|
37
|
+
__classPrivateFieldSet(this, _ConfigImpl_name, actorSpec.name, "f");
|
38
|
+
__classPrivateFieldSet(this, _ConfigImpl_owner, actorSpec.owner, "f");
|
39
|
+
__classPrivateFieldSet(this, _ConfigImpl_version, actorSpec.version, "f");
|
40
|
+
__classPrivateFieldSet(this, _ConfigImpl_assets, Object.freeze(assets), "f");
|
41
|
+
__classPrivateFieldSet(this, _ConfigImpl_webviewAssets, Object.freeze(webviewAssets), "f");
|
42
|
+
}
|
43
|
+
export(namespace) {
|
44
|
+
return DependencySpec.fromPartial({
|
45
|
+
actor: __classPrivateFieldGet(this, _ConfigImpl_instances, "m", _ConfigImpl_newActorSpec).call(this),
|
46
|
+
hostname: resolveActorHostname(NonNull(__classPrivateFieldGet(this, _ConfigImpl_name, "f")), namespace),
|
47
|
+
provides: __classPrivateFieldGet(this, _ConfigImpl_provides, "f").map((definition) => {
|
48
|
+
return PackageSpec.fromPartial({
|
49
|
+
actor: __classPrivateFieldGet(this, _ConfigImpl_instances, "m", _ConfigImpl_newActorSpec).call(this),
|
50
|
+
definition: Definition.toSerializable(definition),
|
51
|
+
});
|
52
|
+
}),
|
53
|
+
uses: __classPrivateFieldGet(this, _ConfigImpl_useQueries, "f"),
|
54
|
+
});
|
55
|
+
}
|
56
|
+
provides(definition) {
|
57
|
+
__classPrivateFieldGet(this, _ConfigImpl_provides, "f").push(definition);
|
58
|
+
}
|
59
|
+
use(definition, options = {}) {
|
60
|
+
const query = PackageQuery.fromPartial({
|
61
|
+
...options,
|
62
|
+
name: options.name ?? PLUGIN_NAME,
|
63
|
+
owner: options.owner,
|
64
|
+
versions: options.versions,
|
65
|
+
typeName: definition.fullName,
|
66
|
+
});
|
67
|
+
__classPrivateFieldGet(this, _ConfigImpl_useQueries, "f").push(query);
|
68
|
+
return __classPrivateFieldGet(this, _ConfigImpl_factory, "f").Build(definition, query);
|
69
|
+
}
|
70
|
+
uses(definition) {
|
71
|
+
return __classPrivateFieldGet(this, _ConfigImpl_useQueries, "f").some((query) => query.typeName === definition.fullName);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
_ConfigImpl_factory = new WeakMap(), _ConfigImpl_name = new WeakMap(), _ConfigImpl_owner = new WeakMap(), _ConfigImpl_provides = new WeakMap(), _ConfigImpl_useQueries = new WeakMap(), _ConfigImpl_version = new WeakMap(), _ConfigImpl_assets = new WeakMap(), _ConfigImpl_webviewAssets = new WeakMap(), _ConfigImpl_instances = new WeakSet(), _ConfigImpl_newActorSpec = function _ConfigImpl_newActorSpec() {
|
75
|
+
return ActorSpec.fromPartial({
|
76
|
+
name: __classPrivateFieldGet(this, _ConfigImpl_name, "f") ?? '',
|
77
|
+
owner: __classPrivateFieldGet(this, _ConfigImpl_owner, "f") ?? '',
|
78
|
+
version: __classPrivateFieldGet(this, _ConfigImpl_version, "f") ?? '',
|
79
|
+
});
|
80
|
+
};
|
@@ -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,mDAAmD;AACnD,eAAO,MAAM,YAAY,EAAE,MAAiB,CAAC;AAE7C,eAAO,MAAM,cAAc,EAAE,MAAgB,CAAC;AAC9C,eAAO,MAAM,aAAa,SAAS,CAAC;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;;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"}
|
package/HostnameUtil.js
ADDED
@@ -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.10.25-next-2024-08-
|
3
|
+
"version": "0.10.25-next-2024-08-19-f27845e8c.0",
|
4
4
|
"license": "BSD-3-Clause",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -23,12 +23,12 @@
|
|
23
23
|
},
|
24
24
|
"types": "./index.d.ts",
|
25
25
|
"dependencies": {
|
26
|
-
"@devvit/protos": "0.10.25-next-2024-08-
|
26
|
+
"@devvit/protos": "0.10.25-next-2024-08-19-f27845e8c.0"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
|
-
"@devvit/eslint-config": "0.10.25-next-2024-08-
|
30
|
-
"@devvit/repo-tools": "0.10.25-next-2024-08-
|
31
|
-
"@devvit/tsconfig": "0.10.25-next-2024-08-
|
29
|
+
"@devvit/eslint-config": "0.10.25-next-2024-08-19-f27845e8c.0",
|
30
|
+
"@devvit/repo-tools": "0.10.25-next-2024-08-19-f27845e8c.0",
|
31
|
+
"@devvit/tsconfig": "0.10.25-next-2024-08-19-f27845e8c.0",
|
32
32
|
"@types/redis-mock": "0.17.1",
|
33
33
|
"eslint": "8.9.0",
|
34
34
|
"lit": "2.2.8",
|
@@ -41,5 +41,5 @@
|
|
41
41
|
"directory": "dist"
|
42
42
|
},
|
43
43
|
"source": "./src/index.ts",
|
44
|
-
"gitHead": "
|
44
|
+
"gitHead": "dbd87ac789657b76c0550b429ce7038d1506e595"
|
45
45
|
}
|