Skip to content

Commit a010500

Browse files
authored
Merge pull request #28 from autogram-is/0.6.0-dev
0.6.0 dev
2 parents 850392c + 396dcab commit a010500

File tree

14 files changed

+364
-64
lines changed

14 files changed

+364
-64
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"url": "https://autogram.is"
3232
},
3333
"contributors": [
34-
"Jeff Eaton <jeff@autogram.is> (http://eaton.fyi)",
35-
"Ethan Marcotte <karen@autogram.is> (https://ethanmarcotte.com)",
36-
"Karen McGrane <karen@autogram.is> (https://karenmcgrane.com)"
34+
"Jeff Eaton <jeff@autogram.is> (http://eaton.fyi)",
35+
"Ethan Marcotte <karen@autogram.is> (https://ethanmarcotte.com)",
36+
"Karen McGrane <karen@autogram.is> (https://karenmcgrane.com)"
3737
],
3838
"license": "MIT",
3939
"repository": {
@@ -67,7 +67,6 @@
6767
"@oclif/plugin-plugins": "^2.1.6",
6868
"@sindresorhus/is": "^5.3.0",
6969
"@sindresorhus/slugify": "^2.1.1",
70-
"@types/jsonld": "^1.5.8",
7170
"@vladfrangu/async_event_emitter": "^2.1.2",
7271
"arrify": "^3.0.0",
7372
"chalk": "^5.1.2",
@@ -90,6 +89,7 @@
9089
"open": "^8.4.0",
9190
"prepend-http": "^4.0.0",
9291
"protocolify": "^4.0.0",
92+
"read-pkg-up": "^9.1.0",
9393
"reflect-metadata": "^0.1.13",
9494
"schema-dts": "^1.1.0",
9595
"terminal-link": "^3.0.0",
@@ -112,6 +112,7 @@
112112
"@types/node": "^18.11.0",
113113
"@types/object-hash": "^2.2.1",
114114
"@types/uuid": "^8.3.4",
115+
"@types/jsonld": "^1.5.8",
115116
"oclif": "^3",
116117
"shx": "^0.3.3",
117118
"ts-node": "^10.8.0",

src/cli/commands/db/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,27 @@ export default class GraphInfo extends SgCommand {
2424

2525
if (dbStatus) {
2626
await graph.db.listCollections()
27-
.then(collections => collections.map(collection => {
28-
return {
29-
name: collection.name,
30-
type: (collection.type === 2) ? 'document' : 'edge',
31-
}
32-
}))
27+
.then(async metadata => {
28+
const data: Record<string, unknown>[] = [];
29+
for (let coll of metadata) {
30+
const collection = graph.db.collection(coll.name);
31+
const details = await collection.figures();
32+
data.push({
33+
name: coll.name,
34+
type: (coll.type === 2) ? 'document' : 'edge',
35+
records: details.count.toLocaleString(),
36+
bytes: Number.parseInt(details.figures['documentsSize']).toLocaleString()
37+
});
38+
}
39+
return data;
40+
})
3341
.then(collections => {
3442
this.ux.table(collections, {
3543
name: { header: 'Collection', minWidth: 20 },
3644
type: {},
37-
});
45+
records: {},
46+
bytes: {}
47+
}, { sort: 'type' });
3848
})
3949
}
4050
}

src/cli/commands/project/ga.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ export default class GA extends SgCommand {
1717
const {flags} = await this.parse(GA);
1818

1919
// Obtain user credentials to use for the request
20-
await GoogleTools.authenticate();
20+
await GoogleTools.ServiceAccount.authenticate();
2121

22-
const res = await GoogleTools.analyticsReporting.reports.batchGet({
23-
requestBody: {
24-
reportRequests: [{
25-
viewId: flags.view,
26-
dateRanges: [ { startDate: '14daysAgo', endDate: '7daysAgo' } ],
27-
metrics: [ { expression: 'ga:users', } ],
28-
}],
29-
},
22+
const request = GoogleTools.UniversalAnalytics.buildUaRequest(flags.view, {
23+
dimension: 'page',
24+
pageSize: 10,
3025
});
31-
console.log(res.data.reports?.pop()?.data);
26+
27+
const results = await GoogleTools.UniversalAnalytics.fetchUaReport(request);
28+
this.ux.styledObject(results.data?.rows?.map(value => value.metrics));
3229
}
3330
}

src/cli/commands/screenshot.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export default class Screenshot extends SgCommand {
3131
selector: Flags.string({
3232
summary: 'CSS selector for element to capture',
3333
}),
34+
limit: Flags.integer({
35+
summary: 'Max number of matching elements to capture',
36+
}),
3437
viewport: Flags.string({
3538
summary: 'Page viewport size',
3639
description: "Viewport can be a resolution in 'width,height' format; a preset name (iphone, ipad, hd, or fhd); or the preset 'all', which generates one screenshot for each defined preset.'",
@@ -64,20 +67,19 @@ export default class Screenshot extends SgCommand {
6467
}
6568

6669
async run() {
67-
const {project} = await this.getProjectContext();
6870
const {argv: urls, flags} = await this.parse(Screenshot);
6971

7072
const captureTool = new ScreenshotTool();
7173
captureTool.on('capture', filename => this.ux.info(`Saved ${filename}...`));
7274

7375
const options:Partial<ScreenshotOptions> = {
74-
storage: project.files('storage'),
7576
directory: flags.directory,
7677
viewports: [flags.viewport],
7778
orientation: flags.orientation,
7879
selectors: flags.selector ? [flags.selector] : undefined,
7980
type: flags.format,
8081
fullPage: flags.fullpage,
82+
limit: flags.limit ?? Infinity
8183
}
8284

8385
const crawler = new PlaywrightCrawler({

src/cli/sg-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export abstract class SgCommand extends Command {
101101

102102
try {
103103
const {flags} = await this.parse(this.constructor as typeof SgCommand);
104-
const _configFilePath = is.string(flags.config) ? flags.config : undefined;
105-
project = await Project.config({ _configFilePath });
104+
const options = is.string(flags.config) ? { _configFilePath: flags.config } : undefined;
105+
project = await Project.config(options);
106106
graph = await project.graph();
107107
} catch(error: unknown) {
108108
if (is.error(error)) {

src/model/helpers/unique-url-set.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class UniqueUrlSet extends Set<UniqueUrl> {
2424
const uu = this.parse(value);
2525
if (uu) {
2626
super.add(uu);
27-
this.verifier.add(uu.id);
27+
this.verifier.add(uu.documentId);
2828
} else {
2929
this.unparsable.add(value as string);
3030
}
@@ -35,7 +35,7 @@ export class UniqueUrlSet extends Set<UniqueUrl> {
3535
override has(value: ValidUniqueUrlInput): boolean {
3636
const uu = this.parse(value);
3737
if (uu) {
38-
return this.verifier.has(uu.id);
38+
return this.verifier.has(uu.documentId);
3939
}
4040

4141
return false;
@@ -44,9 +44,9 @@ export class UniqueUrlSet extends Set<UniqueUrl> {
4444
override delete(value: ValidUniqueUrlInput): boolean {
4545
const uu = this.parse(value);
4646
if (uu) {
47-
this.verifier.delete(uu.id);
47+
this.verifier.delete(uu.documentId);
4848
for (const u of this) {
49-
if (u.id === uu.id) {
49+
if (u.documentId === uu.documentId) {
5050
super.delete(u);
5151
}
5252
}

src/model/vertices/vertice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export abstract class Vertice {
4444
} else if (is.array(r)) {
4545
return r.join('/');
4646
} else {
47-
return r.id;
47+
return r.documentId;
4848
}
4949
}
5050

@@ -141,7 +141,7 @@ export abstract class Vertice {
141141
return this._key;
142142
}
143143

144-
get id(): string {
144+
get documentId(): string {
145145
if (is.undefined(this._id)) {
146146
return [this._collection, this.key].join('/');
147147
}

src/services/arango-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ export class ArangoStore {
182182
// When bulk deleting, remove edges first.
183183
for (const edge of input) {
184184
if (isEdge(edge)) {
185-
promises.push(this.db.collection(edge._collection).remove(edge.id));
185+
promises.push(this.db.collection(edge._collection).remove(edge.documentId));
186186
}
187187
}
188188

189189
for (const vertice of input) {
190190
if (!isEdge(vertice)) {
191-
promises.push(this.db.collection(vertice._collection).remove(vertice.id));
191+
promises.push(this.db.collection(vertice._collection).remove(vertice.documentId));
192192
}
193193
}
194194

src/spider/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { mimeGroups } from './helpers/mime.js';
44
import {SpiderHook} from './hooks/index.js';
55
import {EnqueueUrlOptions} from './links/index.js';
66
import {SpiderRequestHandler} from './handlers/index.js';
7+
import {readPackageUp} from 'read-pkg-up';
8+
9+
const pkgData = await readPackageUp();
710

811
export type SpiderOptions = InternalSpiderOptions & Omit<PlaywrightCrawlerOptions,
912
'preNavigationHooks' |
@@ -165,4 +168,5 @@ const defaultSpiderOptions: InternalSpiderOptions = {
165168
urlOptions: {},
166169
parseMimeTypes: mimeGroups.page,
167170
downloadMimeTypes: [],
171+
userAgent: `Spidergram ${pkgData?.packageJson.version}`
168172
};

src/tools/google/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './jwt-auth.js';
2-
export * from './universal-analytics.js';
3-
export * from './pagespeed.js';
1+
export * as ServiceAccount from './jwt-auth.js';
2+
export * as UniversalAnalytics from './universal-analytics.js';
3+
export * as PageSpeed from './pagespeed.js';

0 commit comments

Comments
 (0)