GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nodejs-datastore/src/filter.ts at main · googleapis/nodejs-datastore

This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Expand file tree

/

filter.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
166 lines (153 loc) · 4.27 KB
/

filter.ts

Copy path

File metadata and controls

166 lines (153 loc) · 4.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {Operator, Filter as IFilter} from './query';
import {entity} from './entity';
import Key = entity.Key;
const OP_TO_OPERATOR = new Map([
['=', 'EQUAL'],
['>', 'GREATER_THAN'],
['>=', 'GREATER_THAN_OR_EQUAL'],
['<', 'LESS_THAN'],
['<=', 'LESS_THAN_OR_EQUAL'],
['HAS_ANCESTOR', 'HAS_ANCESTOR'],
['!=', 'NOT_EQUAL'],
['IN', 'IN'],
['NOT_IN', 'NOT_IN'],
]);
enum CompositeOperator {
AND = 'AND',
OR = 'OR',
}
/**
* And filters are composed of many other filters and when they are applied
* then query results are only returned when they pass through all these other
* filters.
*
* @param {EntityFilter[]} filters The list of filters that make up the AND filter.
* @returns {CompositeFilter} A composite AND filter.
*
*/
export function and(filters: EntityFilter[]): CompositeFilter {
return new CompositeFilter(filters, CompositeOperator.AND);
}
/**
* Or filters are composed of many other filters and when they are applied
* then query results are returned when they pass through any of these other
* filters.
*
* @param {EntityFilter[]} filters The list of filters that make up the OR filter.
* @returns {CompositeFilter} A composite OR filter.
*
*/
export function or(filters: EntityFilter[]): CompositeFilter {
return new CompositeFilter(filters, CompositeOperator.OR);
}
/**
* A Filter is a class that contains data for a filter that can be translated
* into a proto when needed.
*
* @see {@link https://cloud.google.com/datastore/docs/concepts/queries#filters| Filters Reference}
*
*/
export abstract class EntityFilter {
/**
* Gets the proto for the filter.
*
*/
// eslint-disable-next-line
abstract toProto(): any;
}
export type AllowedFilterValueType<T> = T extends '__key__'
? Key | Key[]
: unknown;
/**
* A PropertyFilter is a filter that gets applied to a query directly.
*
* @see {@link https://cloud.google.com/datastore/docs/concepts/queries#property_filters| Property filters Reference}
*
* @class
*/
export class PropertyFilter<T extends string>
extends EntityFilter
implements IFilter
{
/**
* Build a Property Filter object.
*
* @param {string} Property The property name that the filter will be applied to.
* @param {Operator} operator The comparison operator that the filter applies.
* @param {any} val The value that the filter compares the property to.
*/
constructor(
public name: T,
public op: Operator,
public val: AllowedFilterValueType<T>,
) {
super();
}
/**
* Gets the proto for the filter.
*
*/
// eslint-disable-next-line
toProto(): any {
return {
propertyFilter: {
property: {
name: this.name,
},
op: OP_TO_OPERATOR.get(this.op),
value: entity.encodeValue(this.val, this.name),
},
};
}
}
/**
* A CompositeFilter is a filter that combines other filters and applies that
* combination to a query.
*
* @see {@link https://cloud.google.com/datastore/docs/concepts/queries#composite_filters| Composite filters Reference}
*
* @class
*/
class CompositeFilter extends EntityFilter {
filters: EntityFilter[];
op: string;
/**
* Build a Composite Filter object.
*
* @param {EntityFilter[]} filters The filters that make up the composite filter.
*/
constructor(filters: EntityFilter[], op: CompositeOperator) {
super();
this.filters = filters;
this.op = op;
}
/**
* Gets the proto for the filter.
*
*/
// eslint-disable-next-line
toProto(): any {
return {
compositeFilter: {
filters: this.filters.map(filter => filter.toProto()),
op: this.op,
},
};
}
}
export function isFilter(filter: any): filter is EntityFilter {
return filter instanceof EntityFilter;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.