@live-change/simple-query 0.9.138
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/README.md +70 -0
- package/package.json +34 -0
- package/tsconfig.json +29 -0
- package/typedoc.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Simple query
|
|
2
|
+
|
|
3
|
+
Library for creating complex live-change db queries and associated indexes with simple DSL
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { User, Channel, Message, UserIdentification } from "./models.js"
|
|
9
|
+
import simpleQuery from "@live-change/simple-query"
|
|
10
|
+
const query = simpleQuery(definition) // use service definition
|
|
11
|
+
|
|
12
|
+
const channelMessagesWithUsersAndIdentificationByTime = query({ // definition
|
|
13
|
+
name: 'channelMessagesWithUsersAndIdentificationByTime',
|
|
14
|
+
properties: {
|
|
15
|
+
channel: {
|
|
16
|
+
type: Channel,
|
|
17
|
+
validation: ['nonEmpty']
|
|
18
|
+
},
|
|
19
|
+
...App.rangeProperties // Range of fetched data
|
|
20
|
+
},
|
|
21
|
+
sources: {
|
|
22
|
+
user: User, // read from model
|
|
23
|
+
message: Message,
|
|
24
|
+
identification: UserIdentfication
|
|
25
|
+
},
|
|
26
|
+
id: ({ user, message, identification }) => message.time
|
|
27
|
+
code(props, { user, message, identification }) => {
|
|
28
|
+
const { channel, ...range } = props
|
|
29
|
+
message.time.inside(range)
|
|
30
|
+
message.channel.eq(channel)
|
|
31
|
+
user.id.eq(message.author)
|
|
32
|
+
identification.id.eq(user.id)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
And it will automatically create index Message_by_channel_time and Message_by_user_channel_time for fast fetching messages by channel and time range, and for fetching messages by user and timeRange. It will also create preparedQuery with defined parameters.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const oldUsers = query({
|
|
41
|
+
properties: {
|
|
42
|
+
expireTime: {
|
|
43
|
+
type: Date,
|
|
44
|
+
validation: ['nonEmpty']
|
|
45
|
+
},
|
|
46
|
+
...App.rangeProperties
|
|
47
|
+
},
|
|
48
|
+
sources: {
|
|
49
|
+
user: User
|
|
50
|
+
},
|
|
51
|
+
code({ expireTime, ...range }, { user }) => {
|
|
52
|
+
user.createdAt.lessThan(expireTime)
|
|
53
|
+
user.createdAt.inside(range) /// sorting and limiting by it would create inside query, and will be slower
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
In this example, it will create index User_by_createdAt, and merge ranges from expireTime and range parameters using range intersection.
|
|
59
|
+
|
|
60
|
+
## Algorithm
|
|
61
|
+
|
|
62
|
+
Fetching always starts with properties/parameters, algoritm finds index or id based queries that can be feed with those parameters. For every found object it runs rangeQuery to find objects associated with it, for every found object it runs next range queries and so on. In observation mode there will be additional reverse queries run on dependent object updates, to find current state on associated objects.
|
|
63
|
+
|
|
64
|
+
For the first example ```channelMessagesWithUsersAndIdentificationByTime``` it works as follows:
|
|
65
|
+
|
|
66
|
+
1. Find and observe all messages that match channel and range using Message_by_channel_time index.
|
|
67
|
+
2. For every found message get and observe User and UserIdentity objects using id.
|
|
68
|
+
3. Return initial results as array of { id: time, user, identification }
|
|
69
|
+
4. If any messages changes, enters or leaves selected range, change User and UserIdentification observations if needed, and update results.
|
|
70
|
+
5. If any user od useridentification changes update results.
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@live-change/simple-query",
|
|
3
|
+
"version": "0.9.138",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "NODE_ENV=test tape tests/*"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-stack.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "BSD-3-Clause",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/live-change/live-change-stack/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-stack",
|
|
18
|
+
"author": {
|
|
19
|
+
"email": "michal@laszczewski.pl",
|
|
20
|
+
"name": "Michał Łaszczewski",
|
|
21
|
+
"url": "https://www.viamage.com/"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@live-change/framework": "0.9.138",
|
|
26
|
+
"pluralize": "^8.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typedoc": "0.28.3",
|
|
30
|
+
"typedoc-plugin-markdown": "^4.6.3",
|
|
31
|
+
"typedoc-plugin-rename-defaults": "^0.7.3"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "b1b605b7f1fa4fc3de4720afbb401e2cfff080cf"
|
|
34
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"sourceMap": true,
|
|
4
|
+
"composite": true,
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
|
|
9
|
+
"target": "ES2020",
|
|
10
|
+
"useDefineForClassFields": true,
|
|
11
|
+
"lib": ["ES2020", "DOM"],
|
|
12
|
+
|
|
13
|
+
/* Linting */
|
|
14
|
+
"strict": false,
|
|
15
|
+
"noUnusedLocals": false,
|
|
16
|
+
"noUnusedParameters": false,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"outDir": "dist",
|
|
19
|
+
"checkJs": false,
|
|
20
|
+
"esModuleInterop": true, // Enable interop for ES modules
|
|
21
|
+
"resolveJsonModule": true, // Allow importing JSON files
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"noImplicitAny": false
|
|
24
|
+
},
|
|
25
|
+
"files": ["src/index.ts"],
|
|
26
|
+
"include": ["src/**/*.ts", "src/**/*.js"],
|
|
27
|
+
"exclude": ["node_modules/@types", "node_modules/**/*.d.ts", "**/*.test.js", "**/CMakeFiles/**"]
|
|
28
|
+
}
|
|
29
|
+
|
package/typedoc.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"entryPoints": ["src/index.ts"],
|
|
3
|
+
"out": "../../docs/docs/simple-query",
|
|
4
|
+
"includeVersion": true,
|
|
5
|
+
"excludePrivate": true,
|
|
6
|
+
"excludeInternal": true,
|
|
7
|
+
"excludeProtected": true,
|
|
8
|
+
"tsconfig": "./tsconfig.json",
|
|
9
|
+
"plugin": [
|
|
10
|
+
"typedoc-plugin-markdown",
|
|
11
|
+
"typedoc-plugin-rename-defaults"
|
|
12
|
+
],
|
|
13
|
+
"sourceLinkTemplate": "https://github.com/live-change/live-change-stack/blob/master/framework/relations-plugin/{path}#L{line}"
|
|
14
|
+
}
|