@riloservices/base 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +255 -2
- package/dist/browser.cjs +39 -0
- package/dist/browser.d.cts +21 -0
- package/dist/browser.d.mts +21 -0
- package/dist/browser.mjs +37 -0
- package/dist/cli.mjs +307 -0
- package/dist/errors-DwVg5fNj.d.cts +24 -0
- package/dist/errors-DwVg5fNj.d.mts +24 -0
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +57 -0
- package/dist/index.d.mts +57 -0
- package/dist/index.mjs +121 -0
- package/dist/key-B7koHuaE.mjs +272 -0
- package/dist/key-DPXUxbGX.cjs +289 -0
- package/dist/mongoose.cjs +21 -0
- package/dist/mongoose.d.cts +29 -0
- package/dist/mongoose.d.mts +29 -0
- package/dist/mongoose.mjs +19 -0
- package/dist/types-CD9NBWdA.d.cts +88 -0
- package/dist/types-CD9NBWdA.d.mts +88 -0
- package/package.json +72 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_key = require("./key-DPXUxbGX.cjs");
|
|
3
|
+
// src/mongoose.ts
|
|
4
|
+
/**
|
|
5
|
+
* Connects Mongoose to one database of your Space with your app key, or with a `rilodb://` link.
|
|
6
|
+
* It makes the same link as `createClient`, and adds the Space's id to the database name. Throws a
|
|
7
|
+
* `RiloKeyError` for input that is missing or is neither, and a `TypeError` when no database is
|
|
8
|
+
* named by `database` or by the link.
|
|
9
|
+
*/
|
|
10
|
+
async function connectMongoose(mongoose, keyOrLink, options) {
|
|
11
|
+
const { database, appName, ...addresses } = options;
|
|
12
|
+
const target = require_key.resolveTarget(keyOrLink, addresses);
|
|
13
|
+
const name = database ?? target.database ?? void 0;
|
|
14
|
+
if (name === void 0 || name === "") throw new TypeError("Say which database to open: give connectMongoose a `database` option, or a rilodb:// link that names one.");
|
|
15
|
+
return mongoose.connect(target.connectLink, {
|
|
16
|
+
dbName: `${name}_${target.spaceId}`,
|
|
17
|
+
...appName === void 0 ? {} : { appName }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.RiloKeyError = require_key.RiloKeyError;
|
|
21
|
+
exports.connectMongoose = connectMongoose;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as AddressOptions } from "./types-CD9NBWdA.cjs";
|
|
2
|
+
import { n as RiloKeyError } from "./errors-DwVg5fNj.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* The part of your Mongoose instance that this uses. Mongoose isn't a dependency of this package:
|
|
5
|
+
* pass the one your app already has.
|
|
6
|
+
*/
|
|
7
|
+
export interface MongooseLike<Connected = unknown> {
|
|
8
|
+
connect(uri: string, options: {
|
|
9
|
+
dbName: string;
|
|
10
|
+
appName?: string;
|
|
11
|
+
}): Promise<Connected>;
|
|
12
|
+
}
|
|
13
|
+
export interface ConnectMongooseOptions extends Omit<AddressOptions, 'filesUrl'> {
|
|
14
|
+
/**
|
|
15
|
+
* The database to open, by the name you gave it, like `salon-prod`. Needed with an app key. A
|
|
16
|
+
* `rilodb://` link that names a database makes this optional.
|
|
17
|
+
*/
|
|
18
|
+
database?: string;
|
|
19
|
+
/** Shown in the Gateway's connection details, to tell apps apart. */
|
|
20
|
+
appName?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Connects Mongoose to one database of your Space with your app key, or with a `rilodb://` link.
|
|
24
|
+
* It makes the same link as `createClient`, and adds the Space's id to the database name. Throws a
|
|
25
|
+
* `RiloKeyError` for input that is missing or is neither, and a `TypeError` when no database is
|
|
26
|
+
* named by `database` or by the link.
|
|
27
|
+
*/
|
|
28
|
+
export declare function connectMongoose<Connected>(mongoose: MongooseLike<Connected>, keyOrLink: string | null | undefined, options: ConnectMongooseOptions): Promise<Connected>;
|
|
29
|
+
export { RiloKeyError };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as AddressOptions } from "./types-CD9NBWdA.mjs";
|
|
2
|
+
import { n as RiloKeyError } from "./errors-DwVg5fNj.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The part of your Mongoose instance that this uses. Mongoose isn't a dependency of this package:
|
|
5
|
+
* pass the one your app already has.
|
|
6
|
+
*/
|
|
7
|
+
export interface MongooseLike<Connected = unknown> {
|
|
8
|
+
connect(uri: string, options: {
|
|
9
|
+
dbName: string;
|
|
10
|
+
appName?: string;
|
|
11
|
+
}): Promise<Connected>;
|
|
12
|
+
}
|
|
13
|
+
export interface ConnectMongooseOptions extends Omit<AddressOptions, 'filesUrl'> {
|
|
14
|
+
/**
|
|
15
|
+
* The database to open, by the name you gave it, like `salon-prod`. Needed with an app key. A
|
|
16
|
+
* `rilodb://` link that names a database makes this optional.
|
|
17
|
+
*/
|
|
18
|
+
database?: string;
|
|
19
|
+
/** Shown in the Gateway's connection details, to tell apps apart. */
|
|
20
|
+
appName?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Connects Mongoose to one database of your Space with your app key, or with a `rilodb://` link.
|
|
24
|
+
* It makes the same link as `createClient`, and adds the Space's id to the database name. Throws a
|
|
25
|
+
* `RiloKeyError` for input that is missing or is neither, and a `TypeError` when no database is
|
|
26
|
+
* named by `database` or by the link.
|
|
27
|
+
*/
|
|
28
|
+
export declare function connectMongoose<Connected>(mongoose: MongooseLike<Connected>, keyOrLink: string | null | undefined, options: ConnectMongooseOptions): Promise<Connected>;
|
|
29
|
+
export { RiloKeyError };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { r as RiloKeyError, t as resolveTarget } from "./key-B7koHuaE.mjs";
|
|
2
|
+
// src/mongoose.ts
|
|
3
|
+
/**
|
|
4
|
+
* Connects Mongoose to one database of your Space with your app key, or with a `rilodb://` link.
|
|
5
|
+
* It makes the same link as `createClient`, and adds the Space's id to the database name. Throws a
|
|
6
|
+
* `RiloKeyError` for input that is missing or is neither, and a `TypeError` when no database is
|
|
7
|
+
* named by `database` or by the link.
|
|
8
|
+
*/
|
|
9
|
+
async function connectMongoose(mongoose, keyOrLink, options) {
|
|
10
|
+
const { database, appName, ...addresses } = options;
|
|
11
|
+
const target = resolveTarget(keyOrLink, addresses);
|
|
12
|
+
const name = database ?? target.database ?? void 0;
|
|
13
|
+
if (name === void 0 || name === "") throw new TypeError("Say which database to open: give connectMongoose a `database` option, or a rilodb:// link that names one.");
|
|
14
|
+
return mongoose.connect(target.connectLink, {
|
|
15
|
+
dbName: `${name}_${target.spaceId}`,
|
|
16
|
+
...appName === void 0 ? {} : { appName }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export { RiloKeyError, connectMongoose };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** `POST /v1/buckets/:bucket/uploads` */
|
|
2
|
+
interface UploadBody {
|
|
3
|
+
/** Where the file goes inside the bucket, folders included, like `avatars/user-42.jpg`. */
|
|
4
|
+
path: string;
|
|
5
|
+
contentType: string;
|
|
6
|
+
/** Bytes. The upload must be exactly this size. */
|
|
7
|
+
size: number;
|
|
8
|
+
}
|
|
9
|
+
/** A signed form post to storage: send `fields`, then the file as the last field, named `file`. */
|
|
10
|
+
interface UploadTicket {
|
|
11
|
+
url: string;
|
|
12
|
+
fields: Record<string, string>;
|
|
13
|
+
expiresAt: string;
|
|
14
|
+
path: string;
|
|
15
|
+
/** Names the upload. `cancelUpload` releases its hold on storage at once. */
|
|
16
|
+
uploadId: string;
|
|
17
|
+
/** The permanent link, for a public bucket only. */
|
|
18
|
+
publicUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What `link` and `links` can set. */
|
|
21
|
+
interface LinkOptions {
|
|
22
|
+
/** Private buckets only: from 1 second to 7 days. The default is one hour. */
|
|
23
|
+
expiresInSeconds?: number;
|
|
24
|
+
}
|
|
25
|
+
/** A link to one file. A public bucket's links are permanent, so `expiresAt` is null. */
|
|
26
|
+
interface FileLink {
|
|
27
|
+
path: string;
|
|
28
|
+
url: string;
|
|
29
|
+
expiresAt: string | null;
|
|
30
|
+
}
|
|
31
|
+
/** A file in a list. */
|
|
32
|
+
interface FileEntry {
|
|
33
|
+
path: string;
|
|
34
|
+
size: number;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
/** Null when the list has no record of the type; `get` always has it. */
|
|
37
|
+
contentType: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** One file, from `get`. */
|
|
40
|
+
interface FileInfo extends FileEntry {
|
|
41
|
+
contentType: string;
|
|
42
|
+
}
|
|
43
|
+
/** What `list` takes. */
|
|
44
|
+
interface ListFilesQuery {
|
|
45
|
+
/** Only paths that start with this text. Add a closing slash to name a folder. */
|
|
46
|
+
prefix?: string;
|
|
47
|
+
/** `/` to list one folder level at a time. Leave it out for a flat list. */
|
|
48
|
+
delimiter?: '/';
|
|
49
|
+
/** The `nextCursor` of the previous page. */
|
|
50
|
+
cursor?: string;
|
|
51
|
+
/** From 1 to 1,000 files and folders in a page. The default is 100. */
|
|
52
|
+
limit?: number;
|
|
53
|
+
}
|
|
54
|
+
/** One page of files and folders. */
|
|
55
|
+
interface FileList {
|
|
56
|
+
files: FileEntry[];
|
|
57
|
+
/** With `delimiter: '/'`: the folders directly under `prefix`, each ending in a slash. */
|
|
58
|
+
folders: string[];
|
|
59
|
+
/** Pass it back as `cursor` for the next page; null on the last. */
|
|
60
|
+
nextCursor: string | null;
|
|
61
|
+
}
|
|
62
|
+
interface FilesBucketView {
|
|
63
|
+
name: string;
|
|
64
|
+
visibility: 'public' | 'private';
|
|
65
|
+
maxFileSize: number;
|
|
66
|
+
allowedTypes: string[];
|
|
67
|
+
}
|
|
68
|
+
/** What `buckets` answers. */
|
|
69
|
+
interface FilesBuckets {
|
|
70
|
+
buckets: FilesBucketView[];
|
|
71
|
+
usage: {
|
|
72
|
+
/** Bytes counted against the storage limit. */
|
|
73
|
+
totalBytes: number;
|
|
74
|
+
limitBytes: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Where a Space is reached. Production needs none of them; they are for local stand-ins. */
|
|
78
|
+
interface AddressOptions {
|
|
79
|
+
/** The domain Spaces live under. Default: `db.services.rilo.studio`. */
|
|
80
|
+
spacesDomain?: string;
|
|
81
|
+
/** The Gateway's port. Default: 27017. */
|
|
82
|
+
port?: number;
|
|
83
|
+
/** A CA file to trust, for a local stand-in with its own certificate. */
|
|
84
|
+
tlsCAFile?: string;
|
|
85
|
+
/** The Files API address. Default: `https://files.<region>.<spacesDomain>`. */
|
|
86
|
+
filesUrl?: string;
|
|
87
|
+
}
|
|
88
|
+
export { FileList as a, LinkOptions as c, UploadTicket as d, FileLink as i, ListFilesQuery as l, FileEntry as n, FilesBucketView as o, FileInfo as r, FilesBuckets as s, AddressOptions as t, UploadBody as u };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** `POST /v1/buckets/:bucket/uploads` */
|
|
2
|
+
interface UploadBody {
|
|
3
|
+
/** Where the file goes inside the bucket, folders included, like `avatars/user-42.jpg`. */
|
|
4
|
+
path: string;
|
|
5
|
+
contentType: string;
|
|
6
|
+
/** Bytes. The upload must be exactly this size. */
|
|
7
|
+
size: number;
|
|
8
|
+
}
|
|
9
|
+
/** A signed form post to storage: send `fields`, then the file as the last field, named `file`. */
|
|
10
|
+
interface UploadTicket {
|
|
11
|
+
url: string;
|
|
12
|
+
fields: Record<string, string>;
|
|
13
|
+
expiresAt: string;
|
|
14
|
+
path: string;
|
|
15
|
+
/** Names the upload. `cancelUpload` releases its hold on storage at once. */
|
|
16
|
+
uploadId: string;
|
|
17
|
+
/** The permanent link, for a public bucket only. */
|
|
18
|
+
publicUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What `link` and `links` can set. */
|
|
21
|
+
interface LinkOptions {
|
|
22
|
+
/** Private buckets only: from 1 second to 7 days. The default is one hour. */
|
|
23
|
+
expiresInSeconds?: number;
|
|
24
|
+
}
|
|
25
|
+
/** A link to one file. A public bucket's links are permanent, so `expiresAt` is null. */
|
|
26
|
+
interface FileLink {
|
|
27
|
+
path: string;
|
|
28
|
+
url: string;
|
|
29
|
+
expiresAt: string | null;
|
|
30
|
+
}
|
|
31
|
+
/** A file in a list. */
|
|
32
|
+
interface FileEntry {
|
|
33
|
+
path: string;
|
|
34
|
+
size: number;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
/** Null when the list has no record of the type; `get` always has it. */
|
|
37
|
+
contentType: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** One file, from `get`. */
|
|
40
|
+
interface FileInfo extends FileEntry {
|
|
41
|
+
contentType: string;
|
|
42
|
+
}
|
|
43
|
+
/** What `list` takes. */
|
|
44
|
+
interface ListFilesQuery {
|
|
45
|
+
/** Only paths that start with this text. Add a closing slash to name a folder. */
|
|
46
|
+
prefix?: string;
|
|
47
|
+
/** `/` to list one folder level at a time. Leave it out for a flat list. */
|
|
48
|
+
delimiter?: '/';
|
|
49
|
+
/** The `nextCursor` of the previous page. */
|
|
50
|
+
cursor?: string;
|
|
51
|
+
/** From 1 to 1,000 files and folders in a page. The default is 100. */
|
|
52
|
+
limit?: number;
|
|
53
|
+
}
|
|
54
|
+
/** One page of files and folders. */
|
|
55
|
+
interface FileList {
|
|
56
|
+
files: FileEntry[];
|
|
57
|
+
/** With `delimiter: '/'`: the folders directly under `prefix`, each ending in a slash. */
|
|
58
|
+
folders: string[];
|
|
59
|
+
/** Pass it back as `cursor` for the next page; null on the last. */
|
|
60
|
+
nextCursor: string | null;
|
|
61
|
+
}
|
|
62
|
+
interface FilesBucketView {
|
|
63
|
+
name: string;
|
|
64
|
+
visibility: 'public' | 'private';
|
|
65
|
+
maxFileSize: number;
|
|
66
|
+
allowedTypes: string[];
|
|
67
|
+
}
|
|
68
|
+
/** What `buckets` answers. */
|
|
69
|
+
interface FilesBuckets {
|
|
70
|
+
buckets: FilesBucketView[];
|
|
71
|
+
usage: {
|
|
72
|
+
/** Bytes counted against the storage limit. */
|
|
73
|
+
totalBytes: number;
|
|
74
|
+
limitBytes: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Where a Space is reached. Production needs none of them; they are for local stand-ins. */
|
|
78
|
+
interface AddressOptions {
|
|
79
|
+
/** The domain Spaces live under. Default: `db.services.rilo.studio`. */
|
|
80
|
+
spacesDomain?: string;
|
|
81
|
+
/** The Gateway's port. Default: 27017. */
|
|
82
|
+
port?: number;
|
|
83
|
+
/** A CA file to trust, for a local stand-in with its own certificate. */
|
|
84
|
+
tlsCAFile?: string;
|
|
85
|
+
/** The Files API address. Default: `https://files.<region>.<spacesDomain>`. */
|
|
86
|
+
filesUrl?: string;
|
|
87
|
+
}
|
|
88
|
+
export { FileList as a, LinkOptions as c, UploadTicket as d, FileLink as i, ListFilesQuery as l, FileEntry as n, FilesBucketView as o, FileInfo as r, FilesBuckets as s, AddressOptions as t, UploadBody as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riloservices/base",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Use a Rilo DB Space from your server with one app key: your databases through the MongoDB driver, and Files.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://db.services.rilo.studio/docs",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"rilo",
|
|
9
|
+
"rilo-db",
|
|
10
|
+
"database",
|
|
11
|
+
"mongodb",
|
|
12
|
+
"mongoose",
|
|
13
|
+
"files",
|
|
14
|
+
"file-upload",
|
|
15
|
+
"storage",
|
|
16
|
+
"client",
|
|
17
|
+
"app-key"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./mongoose": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/mongoose.d.mts",
|
|
37
|
+
"default": "./dist/mongoose.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/mongoose.d.cts",
|
|
41
|
+
"default": "./dist/mongoose.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./browser": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/browser.d.mts",
|
|
47
|
+
"default": "./dist/browser.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/browser.d.cts",
|
|
51
|
+
"default": "./dist/browser.cjs"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"./package.json": "./package.json"
|
|
55
|
+
},
|
|
56
|
+
"bin": {
|
|
57
|
+
"rilo-db": "dist/cli.mjs"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"README.md",
|
|
62
|
+
"LICENSE"
|
|
63
|
+
],
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
},
|
|
67
|
+
"sideEffects": false,
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=20.19"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"mongodb": "^6.10.0 || ^7.0.0"
|
|
73
|
+
}
|
|
74
|
+
}
|